From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 73C8E3855881; Fri, 9 Jun 2023 15:41:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 73C8E3855881 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686325317; bh=SAEXU5XAvQ96FAXZcPs6yYZLI2CNQ/GX9wPZyQd64s0=; h=From:To:Subject:Date:From; b=wpGNH+mZN/3lDj4jpg+wBtzAXgwdotYLZK4X6X0+AIpXqYXJDIqFrJFU5C+OcVt5D xqRq2vVUN2W8gtd1AaruGON0pCuLfTOE13krJxeCWO62BKCg80IEB85Fq34KPDdBYU dwKGJIe9np+cZAR3QsuWp8QtQ5PjeI2dA0TGFzqs= 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 r14-1659] c++: diagnose auto in template arg X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 35d2c40e4ac9ba57ae82e4722e557a2028d0cf13 X-Git-Newrev: d3e2a174b13dd06e63abdb89f3b3040731a73aff Message-Id: <20230609154157.73C8E3855881@sourceware.org> Date: Fri, 9 Jun 2023 15:41:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d3e2a174b13dd06e63abdb89f3b3040731a73aff commit r14-1659-gd3e2a174b13dd06e63abdb89f3b3040731a73aff Author: Jason Merrill Date: Thu Jun 8 19:31:18 2023 -0400 c++: diagnose auto in template arg We were failing to diagnose this Concepts TS feature that didn't make it into C++20 because the 'auto' was getting converted to a template parameter before we checked for it. So also check in cp_parser_simple_type_specifier. The code in cp_parser_template_type_arg that I initially expected to diagnose this seems unreachable because cp_parser_type_id_1 already checks auto. gcc/cp/ChangeLog: * parser.cc (cp_parser_simple_type_specifier): Check for auto in template argument. (cp_parser_template_type_arg): Remove auto checking. gcc/testsuite/ChangeLog: * g++.dg/concepts/auto7.C: New test. * g++.dg/concepts/auto7a.C: New test. Diff: --- gcc/cp/parser.cc | 17 ++++++++--------- gcc/testsuite/g++.dg/concepts/auto7.C | 9 +++++++++ gcc/testsuite/g++.dg/concepts/auto7a.C | 8 ++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index d77fbd20e56..09cba713437 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -19823,15 +19823,19 @@ cp_parser_simple_type_specifier (cp_parser* parser, "only available with " "%<-std=c++14%> or %<-std=gnu++14%>"); } + else if (!flag_concepts_ts && parser->in_template_argument_list_p) + pedwarn (token->location, 0, + "use of % in template argument " + "only available with %<-fconcepts-ts%>"); + else if (!flag_concepts) + pedwarn (token->location, 0, + "use of % in parameter declaration " + "only available with %<-std=c++20%> or %<-fconcepts%>"); else if (cxx_dialect < cxx14) error_at (token->location, "use of % in parameter declaration " "only available with " "%<-std=c++14%> or %<-std=gnu++14%>"); - else if (!flag_concepts) - pedwarn (token->location, 0, - "use of % in parameter declaration " - "only available with %<-std=c++20%> or %<-fconcepts%>"); } else type = make_auto (); @@ -24522,11 +24526,6 @@ cp_parser_template_type_arg (cp_parser *parser) = G_("types may not be defined in template arguments"); r = cp_parser_type_id_1 (parser, CP_PARSER_FLAGS_NONE, true, false, NULL); parser->type_definition_forbidden_message = saved_message; - if (cxx_dialect >= cxx14 && !flag_concepts && type_uses_auto (r)) - { - error ("invalid use of % in template argument"); - r = error_mark_node; - } return r; } diff --git a/gcc/testsuite/g++.dg/concepts/auto7.C b/gcc/testsuite/g++.dg/concepts/auto7.C new file mode 100644 index 00000000000..3cbf5dd8dfc --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto7.C @@ -0,0 +1,9 @@ +// { dg-do compile { target c++14 } } +// { dg-additional-options -fconcepts-ts } + +template struct A { }; +void f(A a) { } +int main() +{ + f(A()); +} diff --git a/gcc/testsuite/g++.dg/concepts/auto7a.C b/gcc/testsuite/g++.dg/concepts/auto7a.C new file mode 100644 index 00000000000..88868f45d1c --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/auto7a.C @@ -0,0 +1,8 @@ +// { dg-do compile { target c++14 } } + +template struct A { }; +void f(A a) { } // { dg-error "auto. in template argument" } +int main() +{ + f(A()); +}