@@ -1339,24 +1339,51 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
1339
1339
// being substituted into a parameter pack. We can find out if that's
1340
1340
// the case now by inspecting the TypeAliasTemplateDecl template
1341
1341
// parameters. Insert Ty's template args into SpecArgs, bundling args
1342
- // passed to a parameter pack into a TemplateArgument::Pack.
1342
+ // passed to a parameter pack into a TemplateArgument::Pack. It also
1343
+ // doesn't know the value of any defaulted args, so collect those now
1344
+ // too.
1343
1345
SmallVector<TemplateArgument> SpecArgs;
1344
1346
{
1345
1347
ArrayRef SubstArgs = Ty->template_arguments ();
1346
- for (const NamedDecl *P : TD->getTemplateParameters ()->asArray ()) {
1347
- if (P->isParameterPack ()) {
1348
+ for (const NamedDecl *Param : TD->getTemplateParameters ()->asArray ()) {
1349
+ // If Param is a parameter pack, pack the remaining arguments.
1350
+ if (Param->isParameterPack ()) {
1348
1351
SpecArgs.push_back (TemplateArgument (SubstArgs));
1349
1352
break ;
1350
1353
}
1351
- // Skip defaulted args.
1352
- if (SubstArgs.empty ()) {
1353
- // If SubstArgs is now empty (we're taking from it each iteration) and
1354
- // this template parameter isn't a pack, then that should mean we're
1355
- // using default values for the remaining template parameters.
1354
+
1355
+ // Take the next argument.
1356
+ if (!SubstArgs.empty ()) {
1357
+ SpecArgs.push_back (SubstArgs.front ());
1358
+ SubstArgs = SubstArgs.drop_front ();
1359
+ continue ;
1360
+ }
1361
+
1362
+ // If SubstArgs is now empty (we're taking from it each iteration) and
1363
+ // this template parameter isn't a pack, then that should mean we're
1364
+ // using default values for the remaining template parameters. Push the
1365
+ // default value for each parameter.
1366
+ if (auto *P = dyn_cast<TemplateTypeParmDecl>(Param)) {
1367
+ assert (P->hasDefaultArgument () &&
1368
+ " expected defaulted template type parameter" );
1369
+ SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1370
+ /* IsNullPtr=*/ false ,
1371
+ /* IsDefaulted=*/ true ));
1372
+ } else if (auto *P = dyn_cast<NonTypeTemplateParmDecl>(Param)) {
1373
+ assert (P->hasDefaultArgument () &&
1374
+ " expected defaulted template non-type parameter" );
1375
+ SpecArgs.push_back (TemplateArgument (P->getDefaultArgument (),
1376
+ /* IsDefaulted=*/ true ));
1377
+ } else if (auto *P = dyn_cast<TemplateTemplateParmDecl>(Param)) {
1378
+ assert (P->hasDefaultArgument () &&
1379
+ " expected defaulted template template parameter" );
1380
+ SpecArgs.push_back (TemplateArgument (
1381
+ P->getDefaultArgument ().getArgument ().getAsTemplate (),
1382
+ /* IsDefaulted=*/ true ));
1383
+ } else {
1384
+ llvm_unreachable (" Unexpected template parameter kind" );
1356
1385
break ;
1357
1386
}
1358
- SpecArgs.push_back (SubstArgs.front ());
1359
- SubstArgs = SubstArgs.drop_front ();
1360
1387
}
1361
1388
}
1362
1389
TemplateArgs Args = {TD->getTemplateParameters (), SpecArgs};
0 commit comments