r256602 - When a namespace alias redeclares a using declaration, point the diagnostic at
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 29 15:42:34 PST 2015
Author: rsmith
Date: Tue Dec 29 17:42:34 2015
New Revision: 256602
URL: http://llvm.org/viewvc/llvm-project?rev=256602&view=rev
Log:
When a namespace alias redeclares a using declaration, point the diagnostic at
the using declaration not at the thing it's using.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/namespace-alias.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=256602&r1=256601&r2=256602&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Dec 29 17:42:34 2015
@@ -8688,9 +8688,9 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope
// 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
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;
Modified: cfe/trunk/test/SemaCXX/namespace-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/namespace-alias.cpp?rev=256602&r1=256601&r2=256602&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/namespace-alias.cpp (original)
+++ cfe/trunk/test/SemaCXX/namespace-alias.cpp Tue Dec 29 17:42:34 2015
@@ -157,3 +157,14 @@ namespace MultipleUnambiguousLookupResul
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'{{$}}}}
+}
More information about the cfe-commits
mailing list