https://gcc.gnu.org/g:d05949558ef1c8eeeb07399174a64f968f70e3ee

commit r15-3046-gd05949558ef1c8eeeb07399174a64f968f70e3ee
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Tue Aug 20 22:17:41 2024 +0200

    c++: Appertain standard attributes after array closing square bracket to 
array type rather than declarator [PR110345]
    
    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).
    
    2024-08-20  Jakub Jelinek  <ja...@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.

Diff:
---
 gcc/cp/decl.cc                            | 5 ++---
 gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C | 4 ++++
 gcc/testsuite/g++.dg/gomp/attrs-3.C       | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 12139e1d8627..7ab73f1031d7 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -13317,9 +13317,8 @@ grokdeclarator (const cp_declarator *declarator,
            /* [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:
diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C 
b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C
new file mode 100644
index 000000000000..67c1a2098430
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-82.C
@@ -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" }
diff --git a/gcc/testsuite/g++.dg/gomp/attrs-3.C 
b/gcc/testsuite/g++.dg/gomp/attrs-3.C
index 7aab6370d499..5658b3a86895 100644
--- a/gcc/testsuite/g++.dg/gomp/attrs-3.C
+++ b/gcc/testsuite/g++.dg/gomp/attrs-3.C
@@ -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" }
 }

Reply via email to