From: John McCall Date: Fri, 11 Dec 2009 02:33:26 +0000 (+0000) Subject: Check if the target of a using decl is already declared in this scope before X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7533ec10b618d360eb8952e62edb5657199acd3;p=clang Check if the target of a using decl is already declared in this scope before doing any of the other redeclaration checks. We were missing a few cases. Fixes PR 5752. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91096 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 75021c2850..7d16e9b2b0 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -2995,6 +2995,21 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig, if (isa(Target)) Target = cast(Target)->getTargetDecl(); + // If the target happens to be one of the previous declarations, we + // don't have a conflict. + // + // FIXME: but we might be increasing its access, in which case we + // should redeclare it. + NamedDecl *NonTag = 0, *Tag = 0; + for (LookupResult::iterator I = Previous.begin(), E = Previous.end(); + I != E; ++I) { + NamedDecl *D = (*I)->getUnderlyingDecl(); + if (D->getCanonicalDecl() == Target->getCanonicalDecl()) + return false; + + (isa(D) ? Tag : NonTag) = D; + } + if (Target->isFunctionOrFunctionTemplate()) { FunctionDecl *FD; if (isa(Target)) @@ -3036,18 +3051,6 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig, // Target is not a function. - // If the target happens to be one of the previous declarations, we - // don't have a conflict. - NamedDecl *NonTag = 0, *Tag = 0; - for (LookupResult::iterator I = Previous.begin(), E = Previous.end(); - I != E; ++I) { - NamedDecl *D = (*I)->getUnderlyingDecl(); - if (D->getCanonicalDecl() == Target->getCanonicalDecl()) - return false; - - (isa(D) ? Tag : NonTag) = D; - } - if (isa(Target)) { // No conflict between a tag and a non-tag. if (!Tag) return false; diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp index e6b8fc1d8f..00d109e675 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp @@ -17,3 +17,17 @@ namespace test0 { using ns1::tag; using ns2::tag; } + +// PR 5752 +namespace test1 { + namespace ns { + void foo(); + } + + using ns::foo; + void foo(int); + + namespace ns { + using test1::foo; + } +}