forked from OSchip/llvm-project
Ensure code generation for friend declarations in class templates.
llvm-svn: 80418
This commit is contained in:
parent
6fd66d4588
commit
970d530a84
|
@ -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,20 +46,28 @@ 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);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -498,6 +498,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) {
|
|||
Function->setObjectOfFriendDecl(WasDeclared);
|
||||
if (!Owner->isDependentContext())
|
||||
DC->makeDeclVisibleInContext(Function);
|
||||
|
||||
Function->setInstantiationOfMemberFunction(D);
|
||||
}
|
||||
|
||||
if (InitFunctionInstantiation(Function, D))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: clang-cc -fsyntax-only -verify %s
|
||||
// RUN: clang-cc %s
|
||||
|
||||
template <typename T> struct Num {
|
||||
T value_;
|
||||
|
@ -38,7 +38,7 @@ int calc1() {
|
|||
|
||||
int calc2() {
|
||||
Num<int> x = 3;
|
||||
Num<int>::Rep<char> n = 10;
|
||||
Num<int>::Rep<char> n = (cast) 10;
|
||||
Num<int> result = x * n;
|
||||
return result.get();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue