From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id DB2863858C53; Wed, 4 May 2022 16:01:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB2863858C53 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 r13-115] c++: parse error with >= in template argument list [PR105436] X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 22399ad6edcd4a2903b05196b59eec3159ceaa38 X-Git-Newrev: 79a1a01cbd0e4a491d7078783131e3f88ca7158d Message-Id: <20220504160158.DB2863858C53@sourceware.org> Date: Wed, 4 May 2022 16:01:58 +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, 04 May 2022 16:01:59 -0000 https://gcc.gnu.org/g:79a1a01cbd0e4a491d7078783131e3f88ca7158d commit r13-115-g79a1a01cbd0e4a491d7078783131e3f88ca7158d Author: Marek Polacek Date: Fri Apr 29 17:03:41 2022 -0400 c++: parse error with >= in template argument list [PR105436] This patch fixes an oversight whereby we treated >= as the end of a template argument. This causes problems in C++14, because in cp_parser_template_argument we go different ways for C++14 and C++17: /* It must be a non-type argument. In C++17 any constant-expression is allowed. */ if (cxx_dialect > cxx14) goto general_expr; so in this testcase in C++14 we get "N" as the template argument but in C++17 it is the whole "N >= 5" expression. So in C++14 the remaining ">= 5" triggered the newly-added diagnostic. PR c++/105436 gcc/cp/ChangeLog: * parser.cc (cp_parser_next_token_ends_template_argument_p): Don't return true for CPP_GREATER_EQ. gcc/testsuite/ChangeLog: * g++.dg/parse/template31.C: New test. Diff: --- gcc/cp/parser.cc | 1 - gcc/testsuite/g++.dg/parse/template31.C | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index a5cbb3e896f..5fa743b5a8e 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -33224,7 +33224,6 @@ cp_parser_next_token_ends_template_argument_p (cp_parser *parser) || ((cxx_dialect != cxx98) && token->type == CPP_RSHIFT) /* For better diagnostics, treat >>= like that too, that shouldn't appear non-nested in template arguments. */ - || token->type == CPP_GREATER_EQ || token->type == CPP_RSHIFT_EQ); } diff --git a/gcc/testsuite/g++.dg/parse/template31.C b/gcc/testsuite/g++.dg/parse/template31.C new file mode 100644 index 00000000000..a5693e851f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/template31.C @@ -0,0 +1,4 @@ +// PR c++/105436 + +template struct A; +template A= 5> f();