Enable inline namespaces in C++03 as an extension.
authorSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 31 Aug 2010 00:36:45 +0000 (00:36 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Tue, 31 Aug 2010 00:36:45 +0000 (00:36 +0000)
llvm-svn: 112566

clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/Parser.cpp
clang/test/CXX/dcl.dcl/basic.namespace/namespace.def/p1.cpp

index d9d5014476ad13f3f652f41537dcacf4592a6043..646fd0d1bfb6c43b01df3e4da87773ad46b364ed 100644 (file)
@@ -154,6 +154,8 @@ def err_illegal_decl_reference_to_reference : Error<
   "%0 declared as a reference to a reference">;
 def err_rvalue_reference : Error<
   "rvalue references are only allowed in C++0x">;
+def ext_inline_namespace : Extension<
+  "inline namespaces are a C++0x feature">;
 def err_argument_required_after_attribute : Error<
   "argument required after attribute">;
 def err_missing_param : Error<"expected parameter declarator">;
index 1f81202f014a3bd40923a7dd995f4fbaf764584c..0c68f7664e652f350b29782bb91710f23b9788e4 100644 (file)
@@ -324,8 +324,8 @@ Parser::DeclGroupPtrTy Parser::ParseDeclaration(unsigned Context,
     SingleDecl = ParseDeclarationStartingWithTemplate(Context, DeclEnd);
     break;
   case tok::kw_inline:
-    // Could be the start of an inline namespace.
-    if (getLang().CPlusPlus0x && NextToken().is(tok::kw_namespace)) {
+    // Could be the start of an inline namespace. Allowed as an ext in C++03.
+    if (getLang().CPlusPlus && NextToken().is(tok::kw_namespace)) {
       if (Attr.HasAttr)
         Diag(Attr.Range.getBegin(), diag::err_attributes_not_allowed)
           << Attr.Range;
index 26d460c6ffbf593e93a336bfe572939b99405e0c..b277156a0d069e039cf5b4b694b5db32bd37d510 100644 (file)
@@ -103,6 +103,10 @@ Decl *Parser::ParseNamespace(unsigned Context,
     return 0;
   }
 
+  // If we're still good, complain about inline namespaces in non-C++0x now.
+  if (!getLang().CPlusPlus0x && InlineLoc.isValid())
+    Diag(InlineLoc, diag::ext_inline_namespace);
+
   // Enter a scope for the namespace.
   ParseScope NamespaceScope(this, Scope::DeclScope);
 
index 54053435322abbb024d7613f8e7058b18f4edcd0..44bd0fbc0c0311210e85863b1bd8dde32dfcc90f 100644 (file)
@@ -484,8 +484,8 @@ Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(CXX0XAttributeList Attr,
     }
 
   case tok::kw_inline:
-    if (getLang().CPlusPlus0x && NextToken().is(tok::kw_namespace)) {
-      // Inline namespaces
+    if (getLang().CPlusPlus && NextToken().is(tok::kw_namespace)) {
+      // Inline namespaces. Allowed as an extension even in C++03.
       SourceLocation DeclEnd;
       return ParseDeclaration(Declarator::FileContext, DeclEnd, Attr);
     }
index 04584dace9a81e7ad3ca657ea3d3cb58b2bb0e23..6ffa873cd46b9612d5546b6fd0970ae670d2b984 100644 (file)
@@ -1,7 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -pedantic %s
+
+// Intentionally compiled as C++03 to test the extension warning.
 
 namespace a {} // original
 namespace a {} // ext
-inline namespace b {} // inline original
-inline namespace b {} // inline ext
-inline namespace {} // inline unnamed
+inline namespace b {} // inline original expected-warning {{inline namespaces are}}
+inline namespace b {} // inline ext expected-warning {{inline namespaces are}}
+inline namespace {} // inline unnamed expected-warning {{inline namespaces are}}