[cfe-dev] Type source info for function template instances.

John McCall rjmccall at apple.com
Thu Feb 18 15:45:51 PST 2010

On Feb 18, 2010, at 3:17 PM, Enea Zaffanella wrote:
> 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.

This is definitely just an oversight;  the fix required is more-or-less what you've proposed, except ideally we would only transform the type once.  If you'd like to look into the bugs this exposes, that would be great;  otherwise, please file a bug on this.


More information about the cfe-dev mailing list