diff mbox series

c++: Appertain standard attributes after array closing square bracket to array type rather than declarator [PR110345]

Message ID Zr5qtfWW4irww7B1@tucnak
State New
Headers show
Series c++: Appertain standard attributes after array closing square bracket to array type rather than declarator [PR110345] | expand

Commit Message

Jakub Jelinek Aug. 15, 2024, 8:53 p.m. UTC
Hi!

For C++ 26 P2552R3 I went through all the spots (except modules) where
attribute-specifier-seq appears in the grammar and tried to construct
a testcase in all those spots, for now for [[deprecated]] attribute.

This is the second issue I found.  The comment already correctly says that
attributes after closing ] appertain to the array type, but we were
appending them to returned_attrs, so effectively applying them to the
declarator (as if they appeared right after declarator-id).

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2024-08-15  Jakub Jelinek  <jakub@redhat.com>

	PR c++/110345
	* decl.cc (grokdeclarator): Apply declarator->std_attributes
	for cdk_array to type, rather than chaining it to returned_attrs.

	* g++.dg/cpp0x/gen-attrs-82.C: New test.
	* g++.dg/gomp/attrs-3.C (foo): Expect different diagnostics for
	omp::directive attribute after closing square bracket of an automatic
	declaration and add a test with the attribute after array's
	declarator-id.



	Jakub

Comments

Jason Merrill Aug. 20, 2024, 12:21 a.m. UTC | #1
On 8/15/24 4:53 PM, Jakub Jelinek wrote:
> Hi!
> 
> For C++ 26 P2552R3 I went through all the spots (except modules) where
> attribute-specifier-seq appears in the grammar and tried to construct
> a testcase in all those spots, for now for [[deprecated]] attribute.
> 
> This is the second issue I found.  The comment already correctly says that
> attributes after closing ] appertain to the array type, but we were
> appending them to returned_attrs, so effectively applying them to the
> declarator (as if they appeared right after declarator-id).
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

> 2024-08-15  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/110345
> 	* decl.cc (grokdeclarator): Apply declarator->std_attributes
> 	for cdk_array to type, rather than chaining it to returned_attrs.
> 
> 	* g++.dg/cpp0x/gen-attrs-82.C: New test.
> 	* g++.dg/gomp/attrs-3.C (foo): Expect different diagnostics for
> 	omp::directive attribute after closing square bracket of an automatic
> 	declaration and add a test with the attribute after array's
> 	declarator-id.
> 
> --- gcc/cp/decl.cc.jj	2024-08-14 18:19:28.000000000 +0200
> +++ gcc/cp/decl.cc	2024-08-15 17:06:22.936426690 +0200
> @@ -13317,9 +13317,8 @@ grokdeclarator (const cp_declarator *dec
>   	    /* [dcl.array]/1:
>   
>   	       The optional attribute-specifier-seq appertains to the
> -	       array.  */
> -	    returned_attrs = attr_chainon (returned_attrs,
> -					   declarator->std_attributes);
> +	       array type.  */
> +	    decl_attributes (&type, declarator->std_attributes, 0);
>   	  break;
>   
>   	case cdk_function:
> --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C.jj	2024-08-15 17:15:47.982435384 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C	2024-08-15 17:16:17.112074964 +0200
> @@ -0,0 +1,4 @@
> +// { dg-do compile { target c++11 } }
> +
> +int a [[gnu::common]] [2];
> +int b[2] [[gnu::common]];	// { dg-warning "'common' attribute does not apply to types" }
> --- gcc/testsuite/g++.dg/gomp/attrs-3.C.jj	2023-09-18 10:37:49.710048827 +0200
> +++ gcc/testsuite/g++.dg/gomp/attrs-3.C	2024-08-15 22:33:44.570617103 +0200
> @@ -35,6 +35,7 @@ foo ()
>     int *[[omp::directive (threadprivate (t3))]] c;		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
>     int &[[omp::directive (threadprivate (t4))]] d = b;		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
>     typedef int T [[omp::directive (threadprivate (t5))]];	// { dg-error "'omp::directive' not allowed to be specified in this context" }
> -  int e[10] [[omp::directive (threadprivate (t6))]];		// { dg-error "'omp::directive' not allowed to be specified in this context" }
> +  int e [[omp::directive (threadprivate (t6))]] [10];		// { dg-error "'omp::directive' not allowed to be specified in this context" }
> +  int f[10] [[omp::directive (threadprivate (t6))]];		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
>     struct [[omp::directive (threadprivate (t7))]] S {};		// { dg-error "'omp::directive' not allowed to be specified in this context" }
>   }
> 
> 
> 	Jakub
>
diff mbox series

Patch

--- gcc/cp/decl.cc.jj	2024-08-14 18:19:28.000000000 +0200
+++ gcc/cp/decl.cc	2024-08-15 17:06:22.936426690 +0200
@@ -13317,9 +13317,8 @@  grokdeclarator (const cp_declarator *dec
 	    /* [dcl.array]/1:
 
 	       The optional attribute-specifier-seq appertains to the
-	       array.  */
-	    returned_attrs = attr_chainon (returned_attrs,
-					   declarator->std_attributes);
+	       array type.  */
+	    decl_attributes (&type, declarator->std_attributes, 0);
 	  break;
 
 	case cdk_function:
--- gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C.jj	2024-08-15 17:15:47.982435384 +0200
+++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C	2024-08-15 17:16:17.112074964 +0200
@@ -0,0 +1,4 @@ 
+// { dg-do compile { target c++11 } }
+
+int a [[gnu::common]] [2];
+int b[2] [[gnu::common]];	// { dg-warning "'common' attribute does not apply to types" }
--- gcc/testsuite/g++.dg/gomp/attrs-3.C.jj	2023-09-18 10:37:49.710048827 +0200
+++ gcc/testsuite/g++.dg/gomp/attrs-3.C	2024-08-15 22:33:44.570617103 +0200
@@ -35,6 +35,7 @@  foo ()
   int *[[omp::directive (threadprivate (t3))]] c;		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
   int &[[omp::directive (threadprivate (t4))]] d = b;		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
   typedef int T [[omp::directive (threadprivate (t5))]];	// { dg-error "'omp::directive' not allowed to be specified in this context" }
-  int e[10] [[omp::directive (threadprivate (t6))]];		// { dg-error "'omp::directive' not allowed to be specified in this context" }
+  int e [[omp::directive (threadprivate (t6))]] [10];		// { dg-error "'omp::directive' not allowed to be specified in this context" }
+  int f[10] [[omp::directive (threadprivate (t6))]];		// { dg-warning "'omp::directive' scoped attribute directive ignored" }
   struct [[omp::directive (threadprivate (t7))]] S {};		// { dg-error "'omp::directive' not allowed to be specified in this context" }
 }