cp_ensure_no_oacc_routine (parser);
bool is_inline = cp_lexer_next_token_is_keyword (parser->lexer, RID_INLINE);
+ const bool topmost_inline_p = is_inline;
if (is_inline)
{
{
identifier = NULL_TREE;
+ bool nested_inline_p = cp_lexer_next_token_is_keyword (parser->lexer,
+ RID_INLINE);
+ if (nested_inline_p && nested_definition_count != 0)
+ {
+ if (cxx_dialect < cxx2a)
+ pedwarn (cp_lexer_peek_token (parser->lexer)->location,
+ OPT_Wpedantic, "nested inline namespace definitions only "
+ "available with -std=c++2a or -std=gnu++2a");
+ cp_lexer_consume_token (parser->lexer);
+ }
+
if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
{
identifier = cp_parser_identifier (parser);
}
if (cp_lexer_next_token_is_not (parser->lexer, CPP_SCOPE))
- break;
+ {
+ /* Don't forget that the innermost namespace might have been
+ marked as inline. Use |= because we cannot overwrite
+ IS_INLINE in case the outermost namespace is inline, but
+ there are no nested inlines. */
+ is_inline |= nested_inline_p;
+ break;
+ }
if (!nested_definition_count && cxx_dialect < cxx17)
pedwarn (input_location, OPT_Wpedantic,
/* Nested namespace names can create new namespaces (unlike
other qualified-ids). */
- if (int count = identifier ? push_namespace (identifier) : 0)
+ if (int count = (identifier
+ ? push_namespace (identifier, nested_inline_p)
+ : 0))
nested_definition_count += count;
else
cp_parser_error (parser, "nested namespace name required");
if (nested_definition_count && attribs)
error_at (token->location,
"a nested namespace definition cannot have attributes");
- if (nested_definition_count && is_inline)
+ if (nested_definition_count && topmost_inline_p)
error_at (token->location,
"a nested namespace definition cannot be inline");
bool has_visibility = handle_namespace_attrs (current_namespace, attribs);
- warning (OPT_Wnamespaces, "namespace %qD entered", current_namespace);
+ warning (OPT_Wnamespaces, "namespace %qD entered", current_namespace);
/* Look for the `{' to validate starting the namespace. */
matching_braces braces;
--- /dev/null
+// P1094R2
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wpedantic" }
+
+namespace A::inline B::C { // { dg-warning "nested inline namespace definitions only" "" { target c++17_down } }
+// { dg-warning "nested namespace definitions only available" "" { target c++14_down } .-1 }
+ int i;
+}
+
+namespace D::E::inline F { // { dg-warning "nested inline namespace definitions only" "" { target c++17_down } }
+// { dg-warning "nested namespace definitions only available" "" { target c++14_down } .-1 }
+ int j;
+}
+
+inline namespace X {
+ int x;
+}
+
+// Make sure the namespaces are marked inline.
+void
+g ()
+{
+ A::B::C::i++;
+ A::C::i++;
+ D::E::j++;
+ D::E::F::j++;
+ X::x++;
+ x++;
+}