* [PATCH] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061]
@ 2022-03-29 8:05 Jakub Jelinek
2022-03-29 20:55 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-03-29 8:05 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and
release branches (so far also bootstrapped/regtested on the above targets
on 11 branch)?
2022-03-29 Jakub Jelinek <jakub@redhat.com>
PR c++/105061
* parser.cc (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.
--- gcc/cp/parser.cc.jj 2022-03-26 08:11:50.030217910 +0100
+++ gcc/cp/parser.cc 2022-03-28 17:30:41.488053848 +0200
@@ -31417,9 +31417,15 @@ cp_parser_template_introduction (cp_pars
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);
@@ -31440,6 +31446,7 @@ cp_parser_template_introduction (cp_pars
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)))
--- gcc/testsuite/g++.dg/concepts/pr105061.C.jj 2022-03-28 17:34:02.051207207 +0200
+++ gcc/testsuite/g++.dg/concepts/pr105061.C 2022-03-28 17:33:14.502882074 +0200
@@ -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 };
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061]
2022-03-29 8:05 [PATCH] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061] Jakub Jelinek
@ 2022-03-29 20:55 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-03-29 20:55 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 3/29/22 04:05, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and
> release branches (so far also bootstrapped/regtested on the above targets
> on 11 branch)?
OK.
> 2022-03-29 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/105061
> * parser.cc (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.
>
> --- gcc/cp/parser.cc.jj 2022-03-26 08:11:50.030217910 +0100
> +++ gcc/cp/parser.cc 2022-03-28 17:30:41.488053848 +0200
> @@ -31417,9 +31417,15 @@ cp_parser_template_introduction (cp_pars
> 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);
> @@ -31440,6 +31446,7 @@ cp_parser_template_introduction (cp_pars
> 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)))
> --- gcc/testsuite/g++.dg/concepts/pr105061.C.jj 2022-03-28 17:34:02.051207207 +0200
> +++ gcc/testsuite/g++.dg/concepts/pr105061.C 2022-03-28 17:33:14.502882074 +0200
> @@ -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 };
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-03-29 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 8:05 [PATCH] c++: Fox template-introduction tentative parsing in class bodies clear colon_corrects_to_scope_p [PR105061] Jakub Jelinek
2022-03-29 20:55 ` Jason Merrill
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).