]> granicus.if.org Git - clang/commitdiff
When a namespace alias redeclares a using declaration, point the diagnostic at
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Dec 2015 23:42:34 +0000 (23:42 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 29 Dec 2015 23:42:34 +0000 (23:42 +0000)
the using declaration not at the thing it's using.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256602 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/namespace-alias.cpp

index b4d6175622daf312566e3cf731cab053b90ced6f..3f6c6b00d902417848f13f41dc6ad9d15ba9efeb 100644 (file)
@@ -8688,9 +8688,9 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc,
 
   // Find the previous declaration and check that we can redeclare it.
   NamespaceAliasDecl *Prev = nullptr; 
-  if (NamedDecl *PrevDecl = PrevR.getAsSingle<NamedDecl>()) {
-    if (NamespaceAliasDecl *AD =
-            dyn_cast<NamespaceAliasDecl>(PrevR.getRepresentativeDecl())) {
+  if (PrevR.isSingleResult()) {
+    NamedDecl *PrevDecl = PrevR.getRepresentativeDecl();
+    if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) {
       // We already have an alias with the same name that points to the same
       // namespace; check that it matches.
       if (AD->getNamespace()->Equals(getNamespaceDecl(ND))) {
@@ -8703,7 +8703,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc,
         return nullptr;
       }
     } else if (isVisible(PrevDecl)) {
-      unsigned DiagID = isa<NamespaceDecl>(PrevDecl)
+      unsigned DiagID = isa<NamespaceDecl>(PrevDecl->getUnderlyingDecl())
                             ? diag::err_redefinition
                             : diag::err_redefinition_different_kind;
       Diag(AliasLoc, DiagID) << Alias;
index 2ba771ed018a46e09b7290e44b9fc1ea5ccb3b20..281ee9962e8b52e3457ee0f6565f17efab624d06 100644 (file)
@@ -157,3 +157,14 @@ namespace MultipleUnambiguousLookupResults {
   int x2 = X::x; // ok, unambiguous
   int y2 = Y::y; // ok, unambiguous
 }
+
+namespace RedeclOfNonNamespace {
+  int a; // expected-note {{previous}}
+  namespace X { int b; }
+  using X::b; // expected-note {{previous}}
+  namespace c {} // expected-note {{previous}}
+
+  namespace a = X; // expected-error {{different kind}}
+  namespace b = X; // expected-error {{different kind}}
+  namespace c = X; // expected-error-re {{redefinition of 'c'{{$}}}}
+}