From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 3E4FF398B176; Wed, 21 Apr 2021 21:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E4FF398B176 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9456] c++: Fix folding of non-dependent BASELINKs [PR95468] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: fef6ee0790de58f16128a0de87571ba7e04b8320 X-Git-Newrev: 1b265d910f27743dc3ea8e4fde6c292df220fb9f Message-Id: <20210421210946.3E4FF398B176@sourceware.org> Date: Wed, 21 Apr 2021 21:09:46 +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: Wed, 21 Apr 2021 21:09:46 -0000 https://gcc.gnu.org/g:1b265d910f27743dc3ea8e4fde6c292df220fb9f commit r9-9456-g1b265d910f27743dc3ea8e4fde6c292df220fb9f Author: Patrick Palka Date: Tue Feb 23 09:40:09 2021 -0500 c++: Fix folding of non-dependent BASELINKs [PR95468] Here, the problem ultimately seems to be that tsubst_copy_and_build, when called with empty args as we do during non-dependent expression folding, doesn't touch BASELINKs at all: it delegates to tsubst_copy which then immediately exits early due to the empty args. This means that the CAST_EXPR int(1) in the BASELINK A::condition never gets folded (as part of folding of the overall CALL_EXPR), which later causes us to crash when performing overload resolution of the rebuilt CALL_EXPR (which is still in terms of this templated BASELINK). This doesn't happen when condition() is a namespace-scope function because then condition is represented by a TEMPLATE_ID_EXPR rather than by a BASELINK, which does get handled directly from tsubst_copy_and_build. This patch fixes this issue by having tsubst_copy_and_build handle BASELINK directly rather than delegating to tsubst_copy, so that it processes BASELINKs even when args is empty. gcc/cp/ChangeLog: PR c++/95468 * pt.c (tsubst_copy_and_build) : New case, copied over from tsubst_copy. gcc/testsuite/ChangeLog: PR c++/95468 * g++.dg/template/non-dependent15.C: New test. (cherry picked from commit 5bd7afb71fca3a5a6e9f8586d86903bae1849193) Diff: --- gcc/cp/pt.c | 5 +++++ gcc/testsuite/g++.dg/template/non-dependent15.C | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cc40ee0bc81..d0bea4a5266 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18787,6 +18787,11 @@ tsubst_copy_and_build (tree t, case SCOPE_REF: RETURN (tsubst_qualified_id (t, args, complain, in_decl, /*done=*/true, /*address_p=*/false)); + + case BASELINK: + RETURN (tsubst_baselink (t, current_nonlambda_class_type (), + args, complain, in_decl)); + case ARRAY_REF: op1 = tsubst_non_call_postfix_expression (TREE_OPERAND (t, 0), args, complain, in_decl); diff --git a/gcc/testsuite/g++.dg/template/non-dependent15.C b/gcc/testsuite/g++.dg/template/non-dependent15.C new file mode 100644 index 00000000000..00dfe26d6ba --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent15.C @@ -0,0 +1,12 @@ +// PR c++/95468 +// { dg-do compile { target c++11 } } + +struct A { + template + static constexpr int condition() { return N; } +}; + +template struct B {}; + +template +using T = B()>;