diff mbox series

c++: Template keyword following :: [PR96082]

Message ID 20200804140530.1837465-1-polacek@redhat.com
State New
Headers show
Series c++: Template keyword following :: [PR96082] | expand

Commit Message

Marek Polacek Aug. 4, 2020, 2:05 p.m. UTC
In r9-4235 I tried to make sure that the template keyword follows
a nested-name-specifier.  :: is a valid nested-name-specifier, so
I also have to check 'globalscope' before giving the error.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10/9?

gcc/cp/ChangeLog:

	PR c++/96082
	* parser.c (cp_parser_elaborated_type_specifier): Allow
	'template' following ::.

gcc/testsuite/ChangeLog:

	PR c++/96082
	* g++.dg/template/template-keyword3.C: New test.
---
 gcc/cp/parser.c                                   |  2 +-
 gcc/testsuite/g++.dg/template/template-keyword3.C | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/template-keyword3.C


base-commit: 7bd72dd5a385dfa6d49cfe640cefc9ed187361d3

Comments

Jason Merrill Aug. 4, 2020, 5:30 p.m. UTC | #1
On 8/4/20 10:05 AM, Marek Polacek wrote:
> In r9-4235 I tried to make sure that the template keyword follows
> a nested-name-specifier.  :: is a valid nested-name-specifier, so
> I also have to check 'globalscope' before giving the error.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10/9?

Why would anyone write that?

The patch is OK.

> gcc/cp/ChangeLog:
> 
> 	PR c++/96082
> 	* parser.c (cp_parser_elaborated_type_specifier): Allow
> 	'template' following ::.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/96082
> 	* g++.dg/template/template-keyword3.C: New test.
> ---
>   gcc/cp/parser.c                                   |  2 +-
>   gcc/testsuite/g++.dg/template/template-keyword3.C | 11 +++++++++++
>   2 files changed, 12 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/template-keyword3.C
> 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index ab088874ba7..3782edd429e 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -18826,7 +18826,7 @@ cp_parser_elaborated_type_specifier (cp_parser* parser,
>         if (!template_p)
>   	cp_parser_parse_tentatively (parser);
>         /* The `template' keyword must follow a nested-name-specifier.  */
> -      else if (!nested_name_specifier)
> +      else if (!nested_name_specifier && !globalscope)
>   	{
>   	  cp_parser_error (parser, "%<template%> must follow a nested-"
>   			   "name-specifier");
> diff --git a/gcc/testsuite/g++.dg/template/template-keyword3.C b/gcc/testsuite/g++.dg/template/template-keyword3.C
> new file mode 100644
> index 00000000000..91af2b3dc02
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/template-keyword3.C
> @@ -0,0 +1,11 @@
> +// PR c++/96082
> +// { dg-do compile { target c++11 } }
> +
> +template <class> class A {};
> +
> +void
> +f ()
> +{
> +  typename::template A <int> a;
> +  ::template A <int> a2;
> +}
> 
> base-commit: 7bd72dd5a385dfa6d49cfe640cefc9ed187361d3
>
Nathan Sidwell Aug. 4, 2020, 6:48 p.m. UTC | #2
On 8/4/20 1:30 PM, Jason Merrill via Gcc-patches wrote:
> On 8/4/20 10:05 AM, Marek Polacek wrote:
>> In r9-4235 I tried to make sure that the template keyword follows
>> a nested-name-specifier.  :: is a valid nested-name-specifier, so
>> I also have to check 'globalscope' before giving the error.
>>
>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/10/9?
> 
> Why would anyone write that?

Users are more ... imaginative than you or me!

> 
> The patch is OK.

nathan
diff mbox series

Patch

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index ab088874ba7..3782edd429e 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -18826,7 +18826,7 @@  cp_parser_elaborated_type_specifier (cp_parser* parser,
       if (!template_p)
 	cp_parser_parse_tentatively (parser);
       /* The `template' keyword must follow a nested-name-specifier.  */
-      else if (!nested_name_specifier)
+      else if (!nested_name_specifier && !globalscope)
 	{
 	  cp_parser_error (parser, "%<template%> must follow a nested-"
 			   "name-specifier");
diff --git a/gcc/testsuite/g++.dg/template/template-keyword3.C b/gcc/testsuite/g++.dg/template/template-keyword3.C
new file mode 100644
index 00000000000..91af2b3dc02
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/template-keyword3.C
@@ -0,0 +1,11 @@ 
+// PR c++/96082
+// { dg-do compile { target c++11 } }
+
+template <class> class A {};
+
+void
+f ()
+{ 
+  typename::template A <int> a;
+  ::template A <int> a2;
+}