diff options
author | Jason Merrill <jason@redhat.com> | 2022-04-13 14:49:04 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2022-05-13 13:39:31 -0400 |
commit | de0b78d1e75e9483b4550abc38b9199c96465dc5 (patch) | |
tree | b0b522298e08269c73f055b010305364326015cd | |
parent | 48b8d5e028abee8869de946bbd7d24d746655d88 (diff) | |
download | gcc-de0b78d1e75e9483b4550abc38b9199c96465dc5.zip gcc-de0b78d1e75e9483b4550abc38b9199c96465dc5.tar.gz gcc-de0b78d1e75e9483b4550abc38b9199c96465dc5.tar.bz2 |
c++: template conversion op [PR101698]
Asking for conversion to a dependent type also makes a BASELINK dependent.
PR c++/101698
gcc/cp/ChangeLog:
* pt.c (tsubst_baselink): Also check dependent optype.
gcc/testsuite/ChangeLog:
* g++.dg/template/conv19.C: New test.
-rw-r--r-- | gcc/cp/pt.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/conv19.C | 34 |
2 files changed, 36 insertions, 1 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cf3bb05..62ea5c4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15426,7 +15426,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 0000000..7a3da93 --- /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 <class T> + operator const T&() const = delete; + + virtual operator const int&() const { + static int res; + return res; + } +}; + +template <class T> +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<int> a; + const int& b = a; + (void)b; +} |