Hello.
In our client application, we need to visit all instantiations of template declarations. While at it, we were surprised to notice that the instantiations of function template declarations are provided with a TypeSourceInfo object that seems to be an exact copy of the one found in the corresponding templated decl.
In fact, method VisitFunctionDecl() in SemaTemplateInstantiationDecl.cpp does the following:
FunctionDecl *Function =
FunctionDecl::Create(SemaRef.Context, DC, D->getLocation(),
D->getDeclName(), T, D->getTypeSourceInfo(),
D->getStorageClass(),
D->isInlineSpecified(),
D->hasWrittenPrototype());
so that in the instantiated function,
the function type T has been modified by instantiation
QualType T = SubstFunctionType(D, Params);
but the type source info D->getTypeSourceInfo() is passed unmodified.
Apparently, this is different from what is done by other instantiating visitors, such as those for VarDecl and FieldDecl. For instance, for the case of VarDecl, we have the following:
// Do substitution on the type of the declaration
TypeSourceInfo *DI = SemaRef.SubstType(D->getTypeSourceInfo(),
TemplateArgs,
D->getTypeSpecStartLoc(),
D->getDeclName());
// Build the instantiated declaration
VarDecl *Var = VarDecl::Create(SemaRef.Context, Owner,
D->getLocation(), D->getIdentifier(),
DI->getType(), DI,
D->getStorageClass());
Are these different behaviors really meant?
If so, for what reasons?
We have tried a tentative implementation change (attached for your convenience) where we also compute the instantiation for the type source info of all kinds of functions (i.e., including CXXMethodDecl).
This passes all but 2 of the clang tests:
Failing Tests (2):
Clang :: CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.elab/p3.cpp
Clang :: SemaTemplate/instantiate-expr-2.cpp
Expected Passes : 2019
Expected Failures : 14
Unexpected Failures: 2
The first failure is a difference in the expected output;
the second one is an assertion failing.
We would like to hear your opinion on the thing above.
Regards,
Enea Zaffanella.
Subst-Function-TInfo.patch (3.24 KB)