[cfe-commits] r67921 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/SemaCXX/namespace-alias.cpp
Anders Carlsson
andersca at mac.com
Fri Mar 27 23:23:46 PDT 2009
Author: andersca
Date: Sat Mar 28 01:23:46 2009
New Revision: 67921
URL: http://llvm.org/viewvc/llvm-project?rev=67921&view=rev
Log:
Check that the namespace alias doesn't conflict with a previous declaration in this scope.
Added:
cfe/trunk/test/SemaCXX/namespace-alias.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=67921&r1=67920&r2=67921&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Mar 28 01:23:46 2009
@@ -1675,12 +1675,24 @@
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;
}
Added: cfe/trunk/test/SemaCXX/namespace-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/namespace-alias.cpp?rev=67921&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/namespace-alias.cpp (added)
+++ cfe/trunk/test/SemaCXX/namespace-alias.cpp Sat Mar 28 01:23:46 2009
@@ -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'}}
More information about the cfe-commits
mailing list