[cfe-commits] r112564 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/DeclBase.cpp lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Mon Aug 30 17:36:36 PDT 2010


Author: cornedbee
Date: Mon Aug 30 19:36:36 2010
New Revision: 112564

URL: http://llvm.org/viewvc/llvm-project?rev=112564&view=rev
Log:
Enable inline namespaces in the AST.

Added:
    cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=112564&r1=112563&r2=112564&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Aug 30 19:36:36 2010
@@ -219,6 +219,8 @@
 
 /// NamespaceDecl - Represent a C++ namespace.
 class NamespaceDecl : public NamedDecl, public DeclContext {
+  bool IsInline : 1;
+
   SourceLocation LBracLoc, RBracLoc;
 
   // For extended namespace definitions:
@@ -248,28 +250,33 @@
 
   NamespaceDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id)
     : NamedDecl(Namespace, DC, L, Id), DeclContext(Namespace),
-      NextNamespace(0), OrigOrAnonNamespace(0, true) { }
+      IsInline(false), NextNamespace(0), OrigOrAnonNamespace(0, true) { }
 
 public:
   static NamespaceDecl *Create(ASTContext &C, DeclContext *DC,
                                SourceLocation L, IdentifierInfo *Id);
 
-  // \brief Returns true if this is an anonymous namespace declaration.
-  //
-  // For example:
+  /// \brief Returns true if this is an anonymous namespace declaration.
+  ///
+  /// For example:
   /// \code
-  //   namespace {
-  //     ...
-  //   };
-  // \endcode
-  // q.v. C++ [namespace.unnamed]
+  ///   namespace {
+  ///     ...
+  ///   };
+  /// \endcode
+  /// q.v. C++ [namespace.unnamed]
   bool isAnonymousNamespace() const {
     return !getIdentifier();
   }
 
-  /// \brief Returns true if this is a C++0x inline namespace.
+  /// \brief Returns true if this is an inline namespace declaration.
   bool isInline() const {
-    return false;
+    return IsInline;
+  }
+
+  /// \brief Set whether this is an inline namespace declaration.
+  void setInline(bool Inline) {
+    IsInline = Inline;
   }
 
   /// \brief Return the next extended namespace declaration or null if there

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=112564&r1=112563&r2=112564&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Aug 30 19:36:36 2010
@@ -421,6 +421,10 @@
   "static_assert expression is not an integral constant expression">;
 def err_static_assert_failed : Error<"static_assert failed \"%0\"">;
 
+def err_inline_namespace_mismatch : Error<
+  "%select{|non-}0inline namespace "
+  "cannot be reopened as %select{non-|}0inline">;
+
 def err_unexpected_friend : Error<
   "friends can only be classes or functions">;
 def ext_enum_friend : ExtWarn<

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=112564&r1=112563&r2=112564&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Mon Aug 30 19:36:36 2010
@@ -510,7 +510,7 @@
   else if (DeclKind >= Decl::firstRecord && DeclKind <= Decl::lastRecord)
     return cast<RecordDecl>(this)->isAnonymousStructOrUnion();
   else if (DeclKind == Decl::Namespace)
-    return false; // FIXME: Check for C++0x inline namespaces
+    return cast<NamespaceDecl>(this)->isInline();
 
   return false;
 }

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=112564&r1=112563&r2=112564&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Aug 30 19:36:36 2010
@@ -3289,6 +3289,7 @@
   NamespaceDecl *Namespc = NamespaceDecl::Create(Context, CurContext,
     (II ? IdentLoc : LBrace) , II);
   Namespc->setLBracLoc(LBrace);
+  Namespc->setInline(InlineLoc.isValid());
 
   Scope *DeclRegionScope = NamespcScope->getParent();
 
@@ -3311,6 +3312,16 @@
 
     if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
       // This is an extended namespace definition.
+      if (Namespc->isInline() != OrigNS->isInline()) {
+        // inline-ness must match
+        Diag(Namespc->getLocation(), diag::err_inline_namespace_mismatch)
+          << Namespc->isInline();
+        Diag(OrigNS->getLocation(), diag::note_previous_definition);
+        Namespc->setInvalidDecl();
+        // Recover by ignoring the new namespace's inline status.
+        Namespc->setInline(OrigNS->isInline());
+      }
+
       // Attach this namespace decl to the chain of extended namespace
       // definitions.
       OrigNS->setNextNamespace(Namespc);
@@ -3368,6 +3379,16 @@
       assert(!PrevDecl->getNextNamespace());
       Namespc->setOriginalNamespace(PrevDecl->getOriginalNamespace());
       PrevDecl->setNextNamespace(Namespc);
+
+      if (Namespc->isInline() != PrevDecl->isInline()) {
+        // inline-ness must match
+        Diag(Namespc->getLocation(), diag::err_inline_namespace_mismatch)
+          << Namespc->isInline();
+        Diag(PrevDecl->getLocation(), diag::note_previous_definition);
+        Namespc->setInvalidDecl();
+        // Recover by ignoring the new namespace's inline status.
+        Namespc->setInline(PrevDecl->isInline());
+      }
     }
 
     CurContext->addDecl(Namespc);

Added: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp?rev=112564&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp Mon Aug 30 19:36:36 2010
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+namespace NIL {} // expected-note {{previous definition}}
+inline namespace NIL {} // expected-error {{cannot be reopened as inline}}
+inline namespace IL {} // expected-note {{previous definition}}
+namespace IL {} // expected-error {{cannot be reopened as non-inline}}
+
+namespace {} // expected-note {{previous definition}}
+inline namespace {} // expected-error {{cannot be reopened as inline}}
+namespace X {
+  inline namespace {} // expected-note {{previous definition}}
+  namespace {} // expected-error {{cannot be reopened as non-inline}}
+}





More information about the cfe-commits mailing list