diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-01-13 23:06:53 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-01-13 23:06:53 +0000 |
commit | 117c45666c99f1797c708767d7c0ccaa7902ec42 (patch) | |
tree | b99d544309edc5245441de51e019dc95ad09d300 /lib/Sema/SemaLookup.cpp | |
parent | a8c6fea0234bc23de6106a84646dc049cf45e8c8 (diff) |
Make sure to consider non-DeclContext scopes properly when finding
multiple name lookup results in C/Objective-C. Fixes a regression a
caused in r147533, found by Enea Zaffanella!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148154 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index c69022d935..15c3e836a2 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1163,20 +1163,40 @@ bool Sema::LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation) { // Check whether there are any other declarations with the same name // and in the same scope. if (I != IEnd) { - DeclContext *DC = (*I)->getDeclContext()->getRedeclContext(); + // Find the scope in which this declaration was declared (if it + // actually exists in a Scope). + while (S && !S->isDeclScope(D)) + S = S->getParent(); + + // If the scope containing the declaration is the translation unit, + // then we'll need to perform our checks based on the matching + // DeclContexts rather than matching scopes. + if (S && isNamespaceOrTranslationUnitScope(S)) + S = 0; + + // Compute the DeclContext, if we need it. + DeclContext *DC = 0; + if (!S) + DC = (*I)->getDeclContext()->getRedeclContext(); + IdentifierResolver::iterator LastI = I; for (++LastI; LastI != IEnd; ++LastI) { - DeclContext *LastDC - = (*LastI)->getDeclContext()->getRedeclContext(); + if (S) { + // Match based on scope. + if (!S->isDeclScope(*LastI)) + break; + } else { + // Match based on DeclContext. + DeclContext *LastDC + = (*LastI)->getDeclContext()->getRedeclContext(); + if (!LastDC->Equals(DC)) + break; + } + + // If the declaration isn't in the right namespace, skip it. if (!(*LastI)->isInIdentifierNamespace(IDNS)) continue; - - if (!LastDC->Equals(DC)) - break; - - if (!LastDC->isFileContext() && !S->isDeclScope(*LastI)) - break; - + D = R.isHiddenDeclarationVisible()? *LastI : getVisibleDecl(*LastI); if (D) R.addDecl(D); |