From 13e4061bde5ca7929d35b763ff2b32888e62d0b1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 29 Dec 2015 23:42:34 +0000 Subject: [PATCH] When a namespace alias redeclares a using declaration, point the diagnostic at 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 | 8 ++++---- test/SemaCXX/namespace-alias.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b4d6175622..3f6c6b00d9 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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()) { - if (NamespaceAliasDecl *AD = - dyn_cast(PrevR.getRepresentativeDecl())) { + if (PrevR.isSingleResult()) { + NamedDecl *PrevDecl = PrevR.getRepresentativeDecl(); + if (NamespaceAliasDecl *AD = dyn_cast(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(PrevDecl) + unsigned DiagID = isa(PrevDecl->getUnderlyingDecl()) ? diag::err_redefinition : diag::err_redefinition_different_kind; Diag(AliasLoc, DiagID) << Alias; diff --git a/test/SemaCXX/namespace-alias.cpp b/test/SemaCXX/namespace-alias.cpp index 2ba771ed01..281ee9962e 100644 --- a/test/SemaCXX/namespace-alias.cpp +++ b/test/SemaCXX/namespace-alias.cpp @@ -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'{{$}}}} +} -- 2.50.1