@@ -1342,6 +1342,9 @@ namespace {
13421342 DeclarationName Entity;
13431343 // Whether to evaluate the C++20 constraints or simply substitute into them.
13441344 bool EvaluateConstraints = true ;
1345+ // Whether Substitution was Incomplete, that is, we tried to substitute in
1346+ // any template arguments which were null.
1347+ bool IsIncomplete = false ;
13451348
13461349 public:
13471350 typedef TreeTransform<TemplateInstantiator> inherited;
@@ -1372,6 +1375,9 @@ namespace {
13721375 // / Returns the name of the entity being instantiated, if any.
13731376 DeclarationName getBaseEntity () { return Entity; }
13741377
1378+ // / Returns whether any substitution so far was incomplete.
1379+ bool getIsIncomplete () const { return IsIncomplete; }
1380+
13751381 // / Sets the "base" location and entity when that
13761382 // / information is known based on another transformation.
13771383 void setBase (SourceLocation Loc, DeclarationName Entity) {
@@ -1418,6 +1424,8 @@ namespace {
14181424 if (TemplateArgs.hasTemplateArgument (Depth, Index)) {
14191425 Result = TemplateArgs (Depth, Index);
14201426 TemplateArgs.setArgument (Depth, Index, TemplateArgument ());
1427+ } else {
1428+ IsIncomplete = true ;
14211429 }
14221430 }
14231431
@@ -1815,8 +1823,10 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
18151823 // template arguments in a function template, but there were some
18161824 // arguments left unspecified.
18171825 if (!TemplateArgs.hasTemplateArgument (TTP->getDepth (),
1818- TTP->getPosition ()))
1826+ TTP->getPosition ())) {
1827+ IsIncomplete = true ;
18191828 return D;
1829+ }
18201830
18211831 TemplateArgument Arg = TemplateArgs (TTP->getDepth (), TTP->getPosition ());
18221832
@@ -1962,8 +1972,10 @@ TemplateName TemplateInstantiator::TransformTemplateName(
19621972 // template arguments in a function template, but there were some
19631973 // arguments left unspecified.
19641974 if (!TemplateArgs.hasTemplateArgument (TTP->getDepth (),
1965- TTP->getPosition ()))
1975+ TTP->getPosition ())) {
1976+ IsIncomplete = true ;
19661977 return Name;
1978+ }
19671979
19681980 TemplateArgument Arg = TemplateArgs (TTP->getDepth (), TTP->getPosition ());
19691981
@@ -2045,8 +2057,10 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
20452057 // template arguments in a function template, but there were some
20462058 // arguments left unspecified.
20472059 if (!TemplateArgs.hasTemplateArgument (NTTP->getDepth (),
2048- NTTP->getPosition ()))
2060+ NTTP->getPosition ())) {
2061+ IsIncomplete = true ;
20492062 return E;
2063+ }
20502064
20512065 TemplateArgument Arg = TemplateArgs (NTTP->getDepth (), NTTP->getPosition ());
20522066
@@ -2465,6 +2479,7 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
24652479 // template arguments in a function template class, but there were some
24662480 // arguments left unspecified.
24672481 if (!TemplateArgs.hasTemplateArgument (T->getDepth (), T->getIndex ())) {
2482+ IsIncomplete = true ;
24682483 TemplateTypeParmTypeLoc NewTL
24692484 = TLB.push <TemplateTypeParmTypeLoc>(TL.getType ());
24702485 NewTL.setNameLoc (TL.getNameLoc ());
@@ -2836,7 +2851,8 @@ TypeSourceInfo *Sema::SubstType(TypeLoc TL,
28362851// / Deprecated form of the above.
28372852QualType Sema::SubstType (QualType T,
28382853 const MultiLevelTemplateArgumentList &TemplateArgs,
2839- SourceLocation Loc, DeclarationName Entity) {
2854+ SourceLocation Loc, DeclarationName Entity,
2855+ bool *IsIncompleteSubstitution) {
28402856 assert (!CodeSynthesisContexts.empty () &&
28412857 " Cannot perform an instantiation without some context on the "
28422858 " instantiation stack" );
@@ -2847,7 +2863,10 @@ QualType Sema::SubstType(QualType T,
28472863 return T;
28482864
28492865 TemplateInstantiator Instantiator (*this , TemplateArgs, Loc, Entity);
2850- return Instantiator.TransformType (T);
2866+ QualType QT = Instantiator.TransformType (T);
2867+ if (IsIncompleteSubstitution && Instantiator.getIsIncomplete ())
2868+ *IsIncompleteSubstitution = true ;
2869+ return QT;
28512870}
28522871
28532872static bool NeedsInstantiationAsFunctionType (TypeSourceInfo *T) {
0 commit comments