Complete the implementation of N4230, Nested namespace definition.
authorVille Voutilainen <ville.voutilainen@gmail.com>
Mon, 21 Sep 2015 15:50:30 +0000 (18:50 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Mon, 21 Sep 2015 15:50:30 +0000 (18:50 +0300)
/c-family
2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>

Complete the implementation of N4230, Nested namespace definition.
* c-cppbuiltin.c: Add __cpp_namespace_attributes and
__cpp_nested_namespace_definitions.

/cp
2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>

Complete the implementation of N4230, Nested namespace definition.
* parser.c (cp_parser_namespace_definition): Support namespace
attributes both before and after the namespace identifier.

/testsuite
2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>

Complete the implementation of N4230, Nested namespace definition.
* g++.dg/cpp1y/feat-cxx11-neg.C: Add tests for C++17 namespace
attributes and nested namespace definitions.
* g++.dg/cpp1y/feat-cxx98-neg.C: Likewise.
* g++.dg/cpp1z/feat-cxx1z.C: Likewise.
* g++.dg/cpp1y/feat-cxx14-neg.C: New.
* g++.dg/cpp1z/namespace-attribs.C: Likewise.
* g++.dg/cpp1z/nested-namespace-def1.C: Add tests for attributes
appearing before the namespace identifier.

From-SVN: r227977

gcc/c-family/ChangeLog
gcc/c-family/c-cppbuiltin.c
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C
gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C
gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/nested-namespace-def1.C

index b45b53e31fe291519889f9e8107a8737a96a817b..5fa1a727c374d8838a5a3d84ef1e00ada5ba77c9 100644 (file)
@@ -1,3 +1,9 @@
+2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Complete the implementation of N4230, Nested namespace definition.
+       * c-cppbuiltin.c: Add __cpp_namespace_attributes and
+       __cpp_nested_namespace_definitions.
+
 2015-09-18  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * c-pragma.c (handle_pragma_diagnostic): Fix wrong return.
index 0e45a576e9b180c4ab474f94bc8166a9f0880ea7..b222a9f263b1da7106701b5be39a0188c320d3cc 100644 (file)
@@ -870,6 +870,8 @@ c_cpp_builtins (cpp_reader *pfile)
        {
          /* Set feature test macros for C++1z.  */
          cpp_define (pfile, "__cpp_static_assert=201411");
+         cpp_define (pfile, "__cpp_namespace_attributes=201411");
+         cpp_define (pfile, "__cpp_nested_namespace_definitions=201411");
        }
       if (flag_concepts)
        /* Use a value smaller than the 201507 specified in
index ab71f92d5019888c4b5c5b769bc90edfd70e6cbc..279d2f1acd4555c0f8b58fc46a89dcabd8ee522f 100644 (file)
@@ -1,3 +1,9 @@
+2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Complete the implementation of N4230, Nested namespace definition.
+       * parser.c (cp_parser_namespace_definition): Support namespace
+       attributes both before and after the namespace identifier.
+
 2015-09-19  Trevor Saunders  <tbsaunde@tbsaunde.org>
 
        * cp-gimplify.c (gimplify_must_not_throw_expr): Adjust.
index 2071276dfcb8035516463fec8a06ed1c3060ca20..013418941b11007916d9774279147e97847c3704 100644 (file)
@@ -11645,6 +11645,9 @@ cp_parser_declaration (cp_parser* parser)
               (token2.type == CPP_NAME
                && (cp_lexer_peek_nth_token (parser->lexer, 3)->type
                    != CPP_EQ))
+               || (token2.type == CPP_OPEN_SQUARE
+                   && cp_lexer_peek_nth_token (parser->lexer, 3)->type
+                   == CPP_OPEN_SQUARE)
               /* An unnamed namespace definition.  */
               || token2.type == CPP_OPEN_BRACE
               || token2.keyword == RID_ATTRIBUTE))
@@ -16969,6 +16972,9 @@ cp_parser_namespace_definition (cp_parser* parser)
   /* Look for the `namespace' keyword.  */
   token = cp_parser_require_keyword (parser, RID_NAMESPACE, RT_NAMESPACE);
 
+  /* Parse any specified attributes before the identifier.  */
+  attribs = cp_parser_attributes_opt (parser);
+
   /* Get the name of the namespace.  We do not attempt to distinguish
      between an original-namespace-definition and an
      extension-namespace-definition at this point.  The semantic
@@ -16978,8 +16984,15 @@ cp_parser_namespace_definition (cp_parser* parser)
   else
     identifier = NULL_TREE;
 
-  /* Parse any specified attributes.  */
-  attribs = cp_parser_attributes_opt (parser);
+  /* Parse any specified attributes after the identifier.  */
+  tree post_ident_attribs = cp_parser_attributes_opt (parser);
+  if (post_ident_attribs)
+    {
+      if (attribs)
+        attribs = chainon (attribs, post_ident_attribs);
+      else
+        attribs = post_ident_attribs;
+    }
 
   /* Start the namespace.  */
   push_namespace (identifier);
index 61c3b962782a79561c263e5a6c97fc4b13ddb928..c65469fef03b257a4977852662717418757993ef 100644 (file)
@@ -1,3 +1,15 @@
+2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Complete the implementation of N4230, Nested namespace definition.
+       * g++.dg/cpp1y/feat-cxx11-neg.C: Add tests for C++17 namespace
+       attributes and nested namespace definitions.
+       * g++.dg/cpp1y/feat-cxx98-neg.C: Likewise.
+       * g++.dg/cpp1z/feat-cxx1z.C: Likewise.
+       * g++.dg/cpp1y/feat-cxx14-neg.C: New.
+       * g++.dg/cpp1z/namespace-attribs.C: Likewise.
+       * g++.dg/cpp1z/nested-namespace-def1.C: Add tests for attributes
+       appearing before the namespace identifier.
+
 2015-09-21  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/66415
index 81daa04b4de9a22c194062c9b3a5eb1c9377208e..825d0880f58ff9d37dddf39014fd30236716ede1 100644 (file)
 #  error "__cpp_sized_deallocation" // { dg-error "error" }
 #endif
 
+// C++17 features:
+
+#ifndef __cpp_namespace_attributes
+#  error "__cpp_namespace_attributes" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_nested_namespace_definitions
+#  error "__cpp_nested_namespace_definitions" // { dg-error "error" }
+#endif
+
+
 //  Array TS features:
 
 #ifndef __cpp_runtime_arrays
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14-neg.C
new file mode 100644 (file)
index 0000000..221bd3f
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-do compile { target c++14 } }
+
+// C++17 features:
+
+#ifndef __cpp_namespace_attributes
+#  error "__cpp_namespace_attributes" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_nested_namespace_definitions
+#  error "__cpp_nested_namespace_definitions" // { dg-error "error" }
+#endif
index 9c25fc3780ad390e696590ed59f37db0ac5f44ce..886b3d3df10e651390f84a81e53365d634bfae1d 100644 (file)
 #  error "__cpp_sized_deallocation" // { dg-error "error" }
 #endif
 
+// C++17 features:
+
+#ifndef __cpp_namespace_attributes
+#  error "__cpp_namespace_attributes" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_nested_namespace_definitions
+#  error "__cpp_nested_namespace_definitions" // { dg-error "error" }
+#endif
+
 //  C++11 attributes:
 
 #ifdef __has_cpp_attribute
index b3e742c5f09c5f581cab7866050cf8128eed672e..ead16659b5e5acf8ca0d2b9097bfd138623d45c5 100644 (file)
@@ -6,3 +6,15 @@
 #elif __cpp_static_assert != 201411
 #  error "__cpp_static_assert != 201411"
 #endif
+
+#ifndef __cpp_namespace_attributes
+#  error "__cpp_namespace_attributes"
+#elif __cpp_namespace_attributes != 201411
+#  error "__cpp_namespace_attributes != 201411"
+#endif
+
+#ifndef __cpp_nested_namespace_definitions
+#  error "__cpp_nested_namespace_definitions"
+#elif __cpp_nested_namespace_definitions != 201411
+#  error "__cpp_nested_namespace_definitions != 201411"
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C b/gcc/testsuite/g++.dg/cpp1z/namespace-attribs.C
new file mode 100644 (file)
index 0000000..7dc2173
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-options "-std=c++1z" }
+
+namespace A __attribute ((visibility ("default"))) {}
+
+namespace B [[deprecated]] {} // { dg-warning "ignored" }
+
+namespace __attribute ((visibility ("default"))) C {}
+
+namespace [[deprecated]] D {} // { dg-warning "ignored" }
+
index ebdb70b158474dac1f22f1a7989fc48a3ca499dd..39801742d09d0722cb7ae57b71526fa971a21367 100644 (file)
@@ -17,3 +17,7 @@ namespace G __attribute ((visibility ("default"))) ::H {} // { dg-error "cannot
 
 namespace H [[deprecated]] ::I {} // { dg-error "cannot have attributes|ignored" }
 
+namespace __attribute ((visibility ("default"))) I::J {} // { dg-error "cannot have attributes" }
+
+namespace [[deprecated]] J::K {} // { dg-error "cannot have attributes|ignored" }
+