From: Jason Merrill Date: Wed, 13 Apr 2022 18:49:04 +0000 (-0400) Subject: c++: template conversion op [PR101698] X-Git-Tag: basepoints/gcc-13~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4e00ccef6c706a4a4a6446bffaf4111f98d5771;p=thirdparty%2Fgcc.git c++: template conversion op [PR101698] Asking for conversion to a dependent type also makes a BASELINK dependent. PR c++/101698 gcc/cp/ChangeLog: * pt.cc (tsubst_baselink): Also check dependent optype. gcc/testsuite/ChangeLog: * g++.dg/template/conv19.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 84712e6fc2f7..63c08706377d 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16470,7 +16470,8 @@ tsubst_baselink (tree baselink, tree object_type, tree binfo_type = BINFO_TYPE (BASELINK_BINFO (baselink)); binfo_type = tsubst (binfo_type, args, complain, in_decl); - bool dependent_p = binfo_type != BINFO_TYPE (BASELINK_BINFO (baselink)); + bool dependent_p = (binfo_type != BINFO_TYPE (BASELINK_BINFO (baselink)) + || optype != BASELINK_OPTYPE (baselink)); if (dependent_p) { diff --git a/gcc/testsuite/g++.dg/template/conv19.C b/gcc/testsuite/g++.dg/template/conv19.C new file mode 100644 index 000000000000..7a3da939c1fb --- /dev/null +++ b/gcc/testsuite/g++.dg/template/conv19.C @@ -0,0 +1,34 @@ +// PR c++/101698 +// { dg-do compile { target c++11 } } + +class Base { + public: + template + operator const T&() const = delete; + + virtual operator const int&() const { + static int res; + return res; + } +}; + +template +class Derive : public Base { + public: + operator const T&() const override { + using Y = int; + //static_assert(__is_same_as(T,Y), ""); + + static int res; + + res = Base::operator const Y&(); // OK + res = Base::operator const T&(); // { dg-bogus "deleted" } + return res; + } +}; + +int main() { + Derive a; + const int& b = a; + (void)b; +}