Tested manually on Linux-x64, finishing testing with the full suite
on Linux-PPC64. Ok for trunk?

2018-05-24  Ville Voutilainen  <ville.voutilai...@gmail.com>

    gcc/cp/

    Pedwarn on a non-standard position of a C++ attribute.
    * parser.c (cp_parser_namespace_definition): Pedwarn about attributes
    after the namespace name.

    testsuite/

    Pedwarn on a non-standard position of a C++ attribute.
    * g++.dg/cpp1z/namespace-attribs2.C: New.
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6f51f03..ac68159 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -18588,6 +18588,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));
 	}
diff --git a/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C
new file mode 100644
index 0000000..2049da3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs2.C
@@ -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" }
+

Reply via email to