From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id A33F3395B05E; Fri, 13 May 2022 17:14:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A33F3395B05E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10737] c++: template conversion op [PR101698] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 54d1992376d7880a88778dab20a7cfe8cde32bc3 X-Git-Newrev: f06e1ff97cb383118afed4c87dfa104e7c4b141d Message-Id: <20220513171410.A33F3395B05E@sourceware.org> Date: Fri, 13 May 2022 17:14:10 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2022 17:14:10 -0000 https://gcc.gnu.org/g:f06e1ff97cb383118afed4c87dfa104e7c4b141d commit r10-10737-gf06e1ff97cb383118afed4c87dfa104e7c4b141d Author: Jason Merrill Date: Wed Apr 13 14:49:04 2022 -0400 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. Diff: --- gcc/cp/pt.c | 3 ++- gcc/testsuite/g++.dg/template/conv19.C | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index a29e8fb7ad7..c326a80183f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 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 + 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; +}