// Find the appropriate context according to the above.
DC = CurContext;
+
+ // Skip class contexts. If someone can cite chapter and verse
+ // for this behavior, that would be nice --- it's what GCC and
+ // EDG do, and it seems like a reasonable intent, but the spec
+ // really only says that checks for unqualified existing
+ // declarations should stop at the nearest enclosing namespace,
+ // not that they should only consider the nearest enclosing
+ // namespace.
+ while (DC->isRecord())
+ DC = DC->getParent();
+
+ DeclContext *LookupDC = DC;
+ while (LookupDC->isTransparentContext())
+ LookupDC = LookupDC->getParent();
+
while (true) {
- // Skip class contexts. If someone can cite chapter and verse
- // for this behavior, that would be nice --- it's what GCC and
- // EDG do, and it seems like a reasonable intent, but the spec
- // really only says that checks for unqualified existing
- // declarations should stop at the nearest enclosing namespace,
- // not that they should only consider the nearest enclosing
- // namespace.
- while (DC->isRecord() || DC->isTransparentContext())
- DC = DC->getParent();
-
- LookupQualifiedName(Previous, DC);
+ LookupQualifiedName(Previous, LookupDC);
// TODO: decide what we think about using declarations.
- if (isLocal || !Previous.empty())
+ if (isLocal)
break;
+ if (!Previous.empty()) {
+ DC = LookupDC;
+ break;
+ }
+
if (isTemplateId) {
- if (isa<TranslationUnitDecl>(DC)) break;
+ if (isa<TranslationUnitDecl>(LookupDC)) break;
} else {
- if (DC->isFileContext()) break;
+ if (LookupDC->isFileContext()) break;
}
- DC = DC->getParent();
+ LookupDC = LookupDC->getParent();
}
DCScope = getScopeForDeclContext(S, DC);