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
This commit is contained in:
John McCall 2009-12-11 02:33:26 +00:00
Родитель 60fa3cfd7a
Коммит d7533ec10b
2 изменённых файлов: 29 добавлений и 12 удалений

Просмотреть файл

@ -2995,6 +2995,21 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig,
if (isa<UsingShadowDecl>(Target))
Target = cast<UsingShadowDecl>(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<TagDecl>(D) ? Tag : NonTag) = D;
}
if (Target->isFunctionOrFunctionTemplate()) {
FunctionDecl *FD;
if (isa<FunctionTemplateDecl>(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<TagDecl>(D) ? Tag : NonTag) = D;
}
if (isa<TagDecl>(Target)) {
// No conflict between a tag and a non-tag.
if (!Tag) return false;

Просмотреть файл

@ -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;
}
}