summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaTemplateInstantiate.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2016-02-01 22:31:51 +0000
committerNico Weber <nicolasweber@gmx.de>2016-02-01 22:31:51 +0000
commit118951ce7f8a66acdb8cb0394c1fd8070dcbe6e9 (patch)
treea47f30fb50a1b979f205ebe191b81a1dead9c044 /lib/Sema/SemaTemplateInstantiate.cpp
parent5033bd84e79f48e4c0caa879f77044125d1df228 (diff)
Always build a new TypeSourceInfo for function templates with parameters
RecursiveASTVisitor::TraverseFunctionHelper() traverses a function's ParmVarDecls by going to the function's getTypeSourceInfo if it exists, and `DEF_TRAVERSE_TYPELOC(FunctionProtoType` then goes to the function's ParmVarDecls. For a function template that doesn't have parameters that explicitly depend on the template parameter, we used to be clever and not build a new TypeSourceInfo. That meant that when an instantiation of such a template is visited, its TypeSourceInfo would point to the ParmVarDecls of the template, not of the instantiation, which then confused clients of RecursiveASTVisitor. So don't be clever for function templates that have parameters, even if none of the parameters depend on the type. Fixes PR26257. http://reviews.llvm.org/D16478 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259428 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp22
1 files changed, 6 insertions, 16 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index fb7fc109d2..56858bcc7e 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1512,7 +1512,7 @@ QualType Sema::SubstType(QualType T,
}
static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
- if (T->getType()->isInstantiationDependentType() ||
+ if (T->getType()->isInstantiationDependentType() ||
T->getType()->isVariablyModifiedType())
return true;
@@ -1521,23 +1521,13 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) {
return false;
FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>();
- for (unsigned I = 0, E = FP.getNumParams(); I != E; ++I) {
- ParmVarDecl *P = FP.getParam(I);
-
+ for (ParmVarDecl *P : FP.getParams()) {
// This must be synthesized from a typedef.
if (!P) continue;
- // The parameter's type as written might be dependent even if the
- // decayed type was not dependent.
- if (TypeSourceInfo *TSInfo = P->getTypeSourceInfo())
- if (TSInfo->getType()->isInstantiationDependentType())
- return true;
-
- // TODO: currently we always rebuild expressions. When we
- // properly get lazier about this, we should use the same
- // logic to avoid rebuilding prototypes here.
- if (P->hasDefaultArg())
- return true;
+ // If there are any parameters, a new TypeSourceInfo that refers to the
+ // instantiated parameters must be built.
+ return true;
}
return false;
@@ -1556,7 +1546,7 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T,
assert(!ActiveTemplateInstantiations.empty() &&
"Cannot perform an instantiation without some context on the "
"instantiation stack");
-
+
if (!NeedsInstantiationAsFunctionType(T))
return T;