diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-09-26 07:05:09 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-09-26 07:05:09 +0000 |
commit | 6102d98f3b806cc3f4a66cec27f5560b25ddd675 (patch) | |
tree | 1968c4e0c3c2fea1cc6c5d7975a2296dd8d0067a /lib/Sema/SemaTemplate.cpp | |
parent | d85bea2affdd59d83d1be7d24b97f436484c3625 (diff) |
Fix name lookup for friend class templates to consider anything in a
scope *up to and including* the innermost namespace scope, rather than
just searching in the innermost namespace scope.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 72274525fd..d037f3f3e3 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -579,18 +579,6 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName, true); - } else if (TUK == TUK_Friend) { - // C++ [namespace.memdef]p3: - // [...] When looking for a prior declaration of a class or a function - // declared as a friend, and when the name of the friend class or - // function is neither a qualified name nor a template-id, scopes outside - // the innermost enclosing namespace scope are not considered. - SemanticContext = CurContext; - while (!SemanticContext->isFileContext()) - SemanticContext = SemanticContext->getLookupParent(); - - Previous = LookupQualifiedName(SemanticContext, Name, LookupOrdinaryName, - true); } else { SemanticContext = CurContext; Previous = LookupName(S, Name, LookupOrdinaryName, true); @@ -601,7 +589,27 @@ Sema::CheckClassTemplate(Scope *S, unsigned TagSpec, TagUseKind TUK, if (Previous.begin() != Previous.end()) PrevDecl = *Previous.begin(); - if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S)) + if (PrevDecl && TUK == TUK_Friend) { + // C++ [namespace.memdef]p3: + // [...] When looking for a prior declaration of a class or a function + // declared as a friend, and when the name of the friend class or + // function is neither a qualified name nor a template-id, scopes outside + // the innermost enclosing namespace scope are not considered. + DeclContext *OutermostContext = CurContext; + while (!OutermostContext->isFileContext()) + OutermostContext = OutermostContext->getLookupParent(); + + if (OutermostContext->Equals(PrevDecl->getDeclContext()) || + OutermostContext->Encloses(PrevDecl->getDeclContext())) { + SemanticContext = PrevDecl->getDeclContext(); + } else { + // Declarations in outer scopes don't matter. However, the outermost + // context we computed is the semntic context for our new + // declaration. + PrevDecl = 0; + SemanticContext = OutermostContext; + } + } else if (PrevDecl && !isDeclInScope(PrevDecl, SemanticContext, S)) PrevDecl = 0; // If there is a previous declaration with the same name, check |