aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-08-29 03:16:09 +0000
committerJohn McCall <rjmccall@apple.com>2009-08-29 03:16:09 +0000
commitf181d8a44f5837213eeaee6d71f584b1ab2849cd (patch)
tree15fe88e4f2e1cf77deb0e325d36751286ecf5409 /lib/Sema/SemaTemplateInstantiate.cpp
parent9a5bca34ca09d3a88c2ccb4f53b27cf99de4f182 (diff)
Ensure code generation for friend declarations in class templates.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80418 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 4cb5a276e6..521394b978 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -37,7 +37,7 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D) {
if (!Ctx)
Ctx = D->getDeclContext();
- for (; !Ctx->isFileContext(); Ctx = Ctx->getParent()) {
+ while (!Ctx->isFileContext()) {
// Add template arguments from a class template instantiation.
if (ClassTemplateSpecializationDecl *Spec
= dyn_cast<ClassTemplateSpecializationDecl>(Ctx)) {
@@ -46,18 +46,26 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D) {
break;
Result.addOuterTemplateArguments(&Spec->getTemplateInstantiationArgs());
- continue;
}
// Add template arguments from a function template specialization.
- if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
+ else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Ctx)) {
// FIXME: Check whether this is an explicit specialization.
if (const TemplateArgumentList *TemplateArgs
= Function->getTemplateSpecializationArgs())
Result.addOuterTemplateArguments(TemplateArgs);
-
- continue;
+
+ // If this is a friend declaration and it declares an entity at
+ // namespace scope, take arguments from its lexical parent
+ // instead of its semantic parent.
+ if (Function->getFriendObjectKind() &&
+ Function->getDeclContext()->isFileContext()) {
+ Ctx = Function->getLexicalDeclContext();
+ continue;
+ }
}
+
+ Ctx = Ctx->getParent();
}
return Result;