@@ -1343,6 +1343,9 @@ namespace {
13431343 DeclarationName Entity;
13441344 // Whether to evaluate the C++20 constraints or simply substitute into them.
13451345 bool EvaluateConstraints = true ;
1346+ // Whether Substitution was Incomplete, that is, we tried to substitute in
1347+ // any template arguments which were null.
1348+ bool IsIncomplete = false ;
13461349
13471350 public:
13481351 typedef TreeTransform<TemplateInstantiator> inherited;
@@ -1373,6 +1376,9 @@ namespace {
13731376 // / Returns the name of the entity being instantiated, if any.
13741377 DeclarationName getBaseEntity () { return Entity; }
13751378
1379+ // / Returns whether any substitution so far was incomplete.
1380+ bool getIsIncomplete () const { return IsIncomplete; }
1381+
13761382 // / Sets the "base" location and entity when that
13771383 // / information is known based on another transformation.
13781384 void setBase (SourceLocation Loc, DeclarationName Entity) {
@@ -1419,6 +1425,8 @@ namespace {
14191425 if (TemplateArgs.hasTemplateArgument (Depth, Index)) {
14201426 Result = TemplateArgs (Depth, Index);
14211427 TemplateArgs.setArgument (Depth, Index, TemplateArgument ());
1428+ } else {
1429+ IsIncomplete = true ;
14221430 }
14231431 }
14241432
@@ -1814,8 +1822,10 @@ Decl *TemplateInstantiator::TransformDecl(SourceLocation Loc, Decl *D) {
18141822 // template arguments in a function template, but there were some
18151823 // arguments left unspecified.
18161824 if (!TemplateArgs.hasTemplateArgument (TTP->getDepth (),
1817- TTP->getPosition ()))
1825+ TTP->getPosition ())) {
1826+ IsIncomplete = true ;
18181827 return D;
1828+ }
18191829
18201830 TemplateArgument Arg = TemplateArgs (TTP->getDepth (), TTP->getPosition ());
18211831
@@ -1961,8 +1971,10 @@ TemplateName TemplateInstantiator::TransformTemplateName(
19611971 // template arguments in a function template, but there were some
19621972 // arguments left unspecified.
19631973 if (!TemplateArgs.hasTemplateArgument (TTP->getDepth (),
1964- TTP->getPosition ()))
1974+ TTP->getPosition ())) {
1975+ IsIncomplete = true ;
19651976 return Name;
1977+ }
19661978
19671979 TemplateArgument Arg = TemplateArgs (TTP->getDepth (), TTP->getPosition ());
19681980
@@ -2044,8 +2056,10 @@ TemplateInstantiator::TransformTemplateParmRefExpr(DeclRefExpr *E,
20442056 // template arguments in a function template, but there were some
20452057 // arguments left unspecified.
20462058 if (!TemplateArgs.hasTemplateArgument (NTTP->getDepth (),
2047- NTTP->getPosition ()))
2059+ NTTP->getPosition ())) {
2060+ IsIncomplete = true ;
20482061 return E;
2062+ }
20492063
20502064 TemplateArgument Arg = TemplateArgs (NTTP->getDepth (), NTTP->getPosition ());
20512065
@@ -2464,6 +2478,7 @@ TemplateInstantiator::TransformTemplateTypeParmType(TypeLocBuilder &TLB,
24642478 // template arguments in a function template class, but there were some
24652479 // arguments left unspecified.
24662480 if (!TemplateArgs.hasTemplateArgument (T->getDepth (), T->getIndex ())) {
2481+ IsIncomplete = true ;
24672482 TemplateTypeParmTypeLoc NewTL
24682483 = TLB.push <TemplateTypeParmTypeLoc>(TL.getType ());
24692484 NewTL.setNameLoc (TL.getNameLoc ());
@@ -2835,7 +2850,8 @@ TypeSourceInfo *Sema::SubstType(TypeLoc TL,
28352850// / Deprecated form of the above.
28362851QualType Sema::SubstType (QualType T,
28372852 const MultiLevelTemplateArgumentList &TemplateArgs,
2838- SourceLocation Loc, DeclarationName Entity) {
2853+ SourceLocation Loc, DeclarationName Entity,
2854+ bool *IsIncompleteSubstitution) {
28392855 assert (!CodeSynthesisContexts.empty () &&
28402856 " Cannot perform an instantiation without some context on the "
28412857 " instantiation stack" );
@@ -2846,7 +2862,10 @@ QualType Sema::SubstType(QualType T,
28462862 return T;
28472863
28482864 TemplateInstantiator Instantiator (*this , TemplateArgs, Loc, Entity);
2849- return Instantiator.TransformType (T);
2865+ QualType QT = Instantiator.TransformType (T);
2866+ if (IsIncompleteSubstitution && Instantiator.getIsIncomplete ())
2867+ *IsIncompleteSubstitution = true ;
2868+ return QT;
28502869}
28512870
28522871static bool NeedsInstantiationAsFunctionType (TypeSourceInfo *T) {
0 commit comments