Pedwarn on a non-standard position of a C++ attribute.
authorVille Voutilainen <ville.voutilainen@gmail.com>
Thu, 24 May 2018 19:05:46 +0000 (22:05 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Thu, 24 May 2018 19:05:46 +0000 (22:05 +0300)
From-SVN: r260682

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp0x/gen-attrs-56.C
gcc/testsuite/g++.dg/cpp0x/gen-attrs-64.C
gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C [new file with mode: 0644]

index 10e57ee123f0ae48b577bdc4a6c41dfab69e5351..fdf73d182eb36331e2f62f632e0b497139b2b70a 100644 (file)
@@ -1,3 +1,9 @@
+2018-05-24  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Pedwarn on a non-standard position of a C++ attribute.
+       * parser.c (cp_parser_namespace_definition): Pedwarn about attributes
+       after the namespace name.
+
 2018-05-24  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * cp-tree.h (INDIRECT_TYPE_P): New.
index c0220bf1bec5a4726fc955d2e6f7c398cde692c8..f5a6d940601044c269fbc59cc949b2c3836a0a68 100644 (file)
@@ -18656,6 +18656,11 @@ cp_parser_namespace_definition (cp_parser* parser)
        {
          identifier = cp_parser_identifier (parser);
 
+         if (cp_next_tokens_can_be_std_attribute_p (parser))
+           pedwarn (input_location, OPT_Wpedantic,
+                    "standard attributes on namespaces must precede "
+                    "the namespace name");
+
          /* Parse any attributes specified after the identifier.  */
          attribs = attr_chainon (attribs, cp_parser_attributes_opt (parser));
        }
index f331ed369ace9de3d0dda5efe84dd1f7d801bc6f..f63fff4db5e6119ad3b03fcd96a05195880a1b62 100644 (file)
@@ -2,4 +2,4 @@
 // { dg-do compile { target c++11 } }
 
 namespace foo __attribute__((visibility("default"))) {}
-namespace bar [[gnu::visibility("default")]] {}
+namespace [[gnu::visibility("default")]] bar {}
index c0d48fc88e9671142a3f6ebf56a8aa4118ffc21d..4b335eb2818e19386cffdefa3eb8e54e498cc60c 100644 (file)
@@ -1,4 +1,4 @@
 // PR c++/85140
 // { dg-do compile { target c++11 } }
 
-namespace N alignas() {}       // { dg-error "expected" }
+namespace alignas() N  {}      // { dg-error "expected" }
diff --git a/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C
new file mode 100644 (file)
index 0000000..2049da3
--- /dev/null
@@ -0,0 +1,7 @@
+// { dg-options "-std=c++17" }
+// { dg-additional-options "-pedantic" }
+
+namespace B [[deprecated]] {} // { dg-warning "ignored|must precede" }
+
+namespace [[deprecated]] D {} // { dg-warning "ignored" }
+