]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: template conversion op [PR101698]
authorJason Merrill <jason@redhat.com>
Wed, 13 Apr 2022 18:49:04 +0000 (14:49 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 13 May 2022 16:32:20 +0000 (12:32 -0400)
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.

gcc/cp/pt.c
gcc/testsuite/g++.dg/template/conv19.C [new file with mode: 0644]

index a29e8fb7ad7529e2fb651f25a2d6f1f8cb00c927..c326a80183feae2a6a160a4296c3776b7ee8ae78 100644 (file)
@@ -16139,7 +16139,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 (file)
index 0000000..7a3da93
--- /dev/null
@@ -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;
+}