]> granicus.if.org Git - clang/commitdiff
Check that the namespace alias doesn't conflict with a previous declaration in this...
authorAnders Carlsson <andersca@mac.com>
Sat, 28 Mar 2009 06:23:46 +0000 (06:23 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 28 Mar 2009 06:23:46 +0000 (06:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67921 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/namespace-alias.cpp [new file with mode: 0644]

index 349aafdbda57c0b0dd3cbdb29783c34fb7ce4e1d..4c8437deee1de6bf25da6decd2cdbf68ee6bd305 100644 (file)
@@ -1675,12 +1675,24 @@ void Sema::PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir) {
     S->PushUsingDirective(UDir);
 }
 
-Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *CurScope
+Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S
                                            SourceLocation AliasLoc,
                                            IdentifierInfo *Alias,
                                            const CXXScopeSpec &SS,
                                            SourceLocation NamespaceLoc,
                                            IdentifierInfo *NamespaceName) {
+  
+  // Check if we have a previous declaration with the same name.
+  if (NamedDecl *PrevDecl = LookupName(S, Alias, LookupOrdinaryName)) {
+    // FIXME: If this is a namespace alias decl, and it points to the same 
+    // namespace, we shouldn't warn.
+    unsigned DiagID = isa<NamespaceDecl>(PrevDecl) ? diag::err_redefinition :
+      diag::err_redefinition_different_kind;
+    Diag(AliasLoc, DiagID) << Alias;
+    Diag(PrevDecl->getLocation(), diag::note_previous_definition);
+    return 0;
+  }
+
   return 0;
 }
 
diff --git a/test/SemaCXX/namespace-alias.cpp b/test/SemaCXX/namespace-alias.cpp
new file mode 100644 (file)
index 0000000..7458930
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+namespace N { };
+
+namespace A = N;
+
+int B; // expected-note {{previous definition is here}}
+namespace B = N; // expected-error {{redefinition of 'B' as different kind of symbol}}
+
+namespace C { } // expected-note {{previous definition is here}}
+namespace C = N; // expected-error {{redefinition of 'C'}}