You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Remove written template args from implicit var tpl spec
VarTemplateSpecializationDecl::getTemplateArgsAsWritten() function
should return nullptr in the case of implicit instantiation, as its
ClassTemplateSpecializationDecl counterpart does, and not the arguments
written in DeclRefExpr referencing the specialization in the first
place. Otherwise, for such code:
template <typename>
int VarTpl;
template <typename T>
void tplFn() {
(void)VarTpl<T>; // (1)
}
void fn() {
tplFn<char>();
}
Clang treats the 'char' argument of the VarTpl specialization as if it
were written in the line marked as (1), which is misleading and hardly
makes sense.
Moreover, "template args as written" are stored inside ExplicitInfo
field of VarTemplateSpecializationDecl, but it is documented that it
is not for implicit instantiations.
Moreover, it is assumed in TraverseVarTemplateSpecializationDecl method
of RecursiveASTVisitor that getTemplateArgsAsWritten() returns nullptr
for implicit instantiations, as it is stated in the comment there.
That said, setTemplateArgsAsWritten should be called only for variable
template explicit specializations (it is already done inside
Sema::ActOnVarTemplateSpecialization) and explicit instantiations (hence
'true' is passed to the new SetWrittenArgs parameter
of CheckVarTemplateId function inside Sema::ActOnExplicitInstantiation,
but not when handling expressions referencing a variable template
specialization). InstantiateVariableDefinition function just passes
the arguments from the corresponding declaration. I'm not sure about
instantiating a class template containing a variable template explicit
specialization and thus have tried to leave the logic of the first
overload of TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl
as it was.
0 commit comments