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 | 9acb690827ccf97919358e925dfbb04e205d5486 (patch) | |
tree | 670fe854958b33d9700545c3e9f3a15ba04b5034 /clang/lib/Sema/SemaTemplate.cpp | |
parent | 3dad842b356adf3435b3ec4af518b4bd4a7b5cd9 (diff) | |
download | bcm5719-llvm-9acb690827ccf97919358e925dfbb04e205d5486.tar.gz bcm5719-llvm-9acb690827ccf97919358e925dfbb04e205d5486.zip |
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.
llvm-svn: 82849
Diffstat (limited to 'clang/lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | clang/lib/Sema/SemaTemplate.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 72274525fd0..d037f3f3e38 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/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 |