From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id D86D7388EC10; Thu, 8 Oct 2020 04:06:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D86D7388EC10 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-3714] c++: ICE in dependent_type_p with constrained auto [PR97052] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 6b1b5c255f859e75a2d74ae58a011e846d87a277 X-Git-Newrev: c1c62aec6751678e958ab5c61b2d903a09d7efd9 Message-Id: <20201008040615.D86D7388EC10@sourceware.org> Date: Thu, 8 Oct 2020 04:06:15 +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: Thu, 08 Oct 2020 04:06:16 -0000 https://gcc.gnu.org/g:c1c62aec6751678e958ab5c61b2d903a09d7efd9 commit r11-3714-gc1c62aec6751678e958ab5c61b2d903a09d7efd9 Author: Patrick Palka Date: Thu Oct 8 00:05:41 2020 -0400 c++: ICE in dependent_type_p with constrained auto [PR97052] This patch fixes an "unguarded" call to coerce_template_parms in build_standard_check: processing_template_decl could be zero if we get here during processing of the first 'auto' parameter of an abbreviated function template, or if we're processing the type constraint of a non-templated variable. In the testcase below, this leads to an ICE when coerce_template_parms instantiates C's dependent default template argument. gcc/cp/ChangeLog: PR c++/97052 * constraint.cc (build_type_constraint): Temporarily increment processing_template_decl before calling build_concept_check. * pt.c (make_constrained_placeholder_type): Likewise. gcc/testsuite/ChangeLog: PR c++/97052 * g++.dg/cpp2a/concepts-defarg2.C: New test. Diff: --- gcc/cp/constraint.cc | 2 ++ gcc/cp/pt.c | 2 ++ gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C | 13 +++++++++++++ 3 files changed, 17 insertions(+) diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index d49957a6c4a..050b55ce092 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1427,7 +1427,9 @@ tree build_type_constraint (tree decl, tree args, tsubst_flags_t complain) { tree wildcard = build_nt (WILDCARD_DECL); + ++processing_template_decl; tree check = build_concept_check (decl, wildcard, args, complain); + --processing_template_decl; if (check == error_mark_node) return error_mark_node; return unpack_concept_check (check); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index fc4b9bb7c7f..9a83810b67c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -27928,7 +27928,9 @@ make_constrained_placeholder_type (tree type, tree con, tree args) tree expr = tmpl; if (TREE_CODE (con) == FUNCTION_DECL) expr = ovl_make (tmpl); + ++processing_template_decl; expr = build_concept_check (expr, type, args, tf_warning_or_error); + --processing_template_decl; PLACEHOLDER_TYPE_CONSTRAINTS (type) = expr; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C new file mode 100644 index 00000000000..a63ca4e133d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-defarg2.C @@ -0,0 +1,13 @@ +// PR c++/97052 +// { dg-do compile { target c++20 } } + +template +concept C = true; + +constexpr bool f(C auto) { + return true; +} + +static_assert(f(0)); + +C auto x = 0;