public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10700] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR Date: Tue, 10 May 2022 08:25:41 +0000 (GMT) [thread overview] Message-ID: <20220510082541.460F73887009@sourceware.org> (raw) https://gcc.gnu.org/g:3d8d22d7bd799fbdcddb4762a97c39d6107ee077 commit r10-10700-g3d8d22d7bd799fbdcddb4762a97c39d6107ee077 Author: Jakub Jelinek <jakub@redhat.com> Date: Wed Mar 30 09:16:41 2022 +0200 c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061] The concepts support (in particular template introductions from concepts TS) broke the following testcase, valid unnamed bitfields with dependent types (or even just typedefs) were diagnosed as typos (: instead of correct ::) in template introduction during their tentative parsing. The following patch fixes that by not doing this : to :: correction when member_p is true. 2022-03-30 Jakub Jelinek <jakub@redhat.com> PR c++/105061 * parser.c (cp_parser_template_introduction): If member_p, temporarily clear parser->colon_corrects_to_scope_p around tentative parsing of nested name specifier. * g++.dg/concepts/pr105061.C: New test. (cherry picked from commit 4f2795218a6ba6a7b7b9b18ca7a6e390661e1608) Diff: --- gcc/cp/parser.c | 7 +++++++ gcc/testsuite/g++.dg/concepts/pr105061.C | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 61f2af34688..1499bf5d258 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -29218,9 +29218,15 @@ cp_parser_template_introduction (cp_parser* parser, bool member_p) tree saved_scope = parser->scope; tree saved_object_scope = parser->object_scope; tree saved_qualifying_scope = parser->qualifying_scope; + bool saved_colon_corrects_to_scope_p = parser->colon_corrects_to_scope_p; cp_token *start_token = cp_lexer_peek_token (parser->lexer); + /* In classes don't parse valid unnamed bitfields as invalid + template introductions. */ + if (member_p) + parser->colon_corrects_to_scope_p = false; + /* Look for the optional `::' operator. */ cp_parser_global_scope_opt (parser, /*current_scope_valid_p=*/false); @@ -29241,6 +29247,7 @@ cp_parser_template_introduction (cp_parser* parser, bool member_p) parser->scope = saved_scope; parser->object_scope = saved_object_scope; parser->qualifying_scope = saved_qualifying_scope; + parser->colon_corrects_to_scope_p = saved_colon_corrects_to_scope_p; if (concept_name == error_mark_node || (seen_error () && !concept_definition_p (tmpl_decl))) diff --git a/gcc/testsuite/g++.dg/concepts/pr105061.C b/gcc/testsuite/g++.dg/concepts/pr105061.C new file mode 100644 index 00000000000..3f6f0e4d6e1 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/pr105061.C @@ -0,0 +1,13 @@ +// PR c++/105061 + +template <typename T, int U, int V> +struct A { T : V, u : U; }; +template <int U, int V> +struct B { unsigned : V, u : U; }; +typedef unsigned uns; +template <int U, int V> +struct C { uns : V, u : U; }; + +A<unsigned int, 4, 5> a = { 13 }; +B<5, 6> b = { 26 }; +C<8, 9> c = { 42 };
reply other threads:[~2022-05-10 8:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220510082541.460F73887009@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).