public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: template conversion op [PR101698]
@ 2022-04-14  0:24 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-14  0:24 UTC (permalink / raw)
  To: gcc-patches

Asking for conversion to a dependent type also makes a BASELINK dependent.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/101698

gcc/cp/ChangeLog:

	* pt.cc (tsubst_baselink): Also check dependent optype.

gcc/testsuite/ChangeLog:

	* g++.dg/template/conv19.C: New test.
---
 gcc/cp/pt.cc                           |  3 ++-
 gcc/testsuite/g++.dg/template/conv19.C | 34 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/conv19.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 84712e6fc2f..63c08706377 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 00000000000..7a3da939c1f
--- /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;
+}

base-commit: ad8161e6d7b26d690d90069ae9a129e7ac36892a
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-14  0:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14  0:24 [pushed] c++: template conversion op [PR101698] Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).