From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id C7C843857C4E; Fri, 15 Apr 2022 15:35:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7C843857C4E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8176] c++: wrong error with variadic concept [PR105268] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: a54137c88061c7495728fc6b8dfd0474e812b2cb X-Git-Newrev: ccae4443c8322d9d82a19a1e7c689413a122a478 Message-Id: <20220415153528.C7C843857C4E@sourceware.org> Date: Fri, 15 Apr 2022 15:35:28 +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, 15 Apr 2022 15:35:28 -0000 https://gcc.gnu.org/g:ccae4443c8322d9d82a19a1e7c689413a122a478 commit r12-8176-gccae4443c8322d9d82a19a1e7c689413a122a478 Author: Marek Polacek Date: Thu Apr 14 13:48:15 2022 -0400 c++: wrong error with variadic concept [PR105268] Here we issue a wrong error for the template>> void g(); line in the testcase. I surmise that's because we mistakenly parse C_many as a placeholder-type-specifier, and things go wrong from there. We are in a default argument so we should reject parsing C_many as a placeholder-type-specifier, which would mean creating a new parameter. We want C_many to be a concept-id instead. It's interesting to see why the same problem didn't occur for C_one. In that case, cp_parser_placeholder_type_specifier -> finish_type_constraints -> build_type_constraint -> build_concept_check -> build_standard_check -> coerce_template_parms fails the parse here: 8916 nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0; 8917 if ((nargs - variadic_args_p > nparms && !variadic_p) 8918 || (nargs < nparms - variadic_p 8919 && require_all_args 8920 && !variadic_args_p 8921 && (!use_default_args 8922 || (TREE_VEC_ELT (parms, nargs) != error_mark_node 8923 && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs)))))) 8924 { 8925 bad_nargs: ... 8943 return error_mark_node; because nargs is 2 (the targs are ) while nparms is 1 (for the one 'typename' in the tparam list of C_one). But for C_many variadic_p is true so we don't return error_mark_node but . This patch does not issue any error for the !tentative case because I didn't figure out how to trigger that. So it adds an assert instead. PR c++/105268 gcc/cp/ChangeLog: * parser.cc (cp_parser_placeholder_type_specifier): Return error_mark_node when trying to build up a constrained parameter in a default argument. gcc/testsuite/ChangeLog: * g++.dg/concepts/variadic6.C: New test. Diff: --- gcc/cp/parser.cc | 11 ++++++++++- gcc/testsuite/g++.dg/concepts/variadic6.C | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index bfd16e1ef62..169e6a62f5f 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -20041,7 +20041,16 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc, /* In a template parameter list, a type-parameter can be introduced by type-constraints alone. */ if (processing_template_parmlist && !placeholder) - return build_constrained_parameter (con, proto, args); + { + /* In a default argument we may not be creating new parameters. */ + if (parser->local_variables_forbidden_p & LOCAL_VARS_FORBIDDEN) + { + /* If this assert turns out to be false, do error() instead. */ + gcc_assert (tentative); + return error_mark_node; + } + return build_constrained_parameter (con, proto, args); + } /* Diagnose issues placeholder issues. */ if (!flag_concepts_ts diff --git a/gcc/testsuite/g++.dg/concepts/variadic6.C b/gcc/testsuite/g++.dg/concepts/variadic6.C new file mode 100644 index 00000000000..0b386b0cd6d --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/variadic6.C @@ -0,0 +1,20 @@ +// PR c++/105268 +// { dg-do compile { target concepts } } + +template concept C_one = true; +template concept C_many = true; + +template struct S { }; + +template>> void f(); +template>> void g(); + +void +fn (auto a = S>{}) +{ +} + +void +fn2 (auto a = S>{}) +{ +}