@@ -1311,10 +1311,18 @@ CompilerType TypeSystemClang::CreateRecordType(
13111311}
13121312
13131313namespace {
1314- // / Returns true iff the given TemplateArgument should be represented as an
1315- // / NonTypeTemplateParmDecl in the AST.
1316- bool IsValueParam (const clang::TemplateArgument &argument) {
1317- return argument.getKind () == TemplateArgument::Integral;
1314+ // / Returns the type of the template argument iff the given TemplateArgument
1315+ // / should be represented as an NonTypeTemplateParmDecl in the AST. Returns
1316+ // / a null QualType otherwise.
1317+ QualType GetValueParamType (const clang::TemplateArgument &argument) {
1318+ switch (argument.getKind ()) {
1319+ case TemplateArgument::Integral:
1320+ return argument.getIntegralType ();
1321+ case TemplateArgument::StructuralValue:
1322+ return argument.getStructuralValueType ();
1323+ default :
1324+ return {};
1325+ }
13181326}
13191327
13201328void AddAccessSpecifierDecl (clang::CXXRecordDecl *cxx_record_decl,
@@ -1361,8 +1369,8 @@ static TemplateParameterList *CreateTemplateParameterList(
13611369 if (name && name[0 ])
13621370 identifier_info = &ast.Idents .get (name);
13631371 TemplateArgument const &targ = args[i];
1364- if ( IsValueParam ( targ)) {
1365- QualType template_param_type = targ. getIntegralType ();
1372+ QualType template_param_type = GetValueParamType ( targ);
1373+ if (! template_param_type. isNull ()) {
13661374 template_param_decls.push_back (NonTypeTemplateParmDecl::Create (
13671375 ast, decl_context, SourceLocation (), SourceLocation (), depth, i,
13681376 identifier_info, template_param_type, parameter_pack,
@@ -1380,10 +1388,11 @@ static TemplateParameterList *CreateTemplateParameterList(
13801388 identifier_info = &ast.Idents .get (template_param_infos.GetPackName ());
13811389 const bool parameter_pack_true = true ;
13821390
1383- if (!template_param_infos.GetParameterPack ().IsEmpty () &&
1384- IsValueParam (template_param_infos.GetParameterPack ().Front ())) {
1385- QualType template_param_type =
1386- template_param_infos.GetParameterPack ().Front ().getIntegralType ();
1391+ QualType template_param_type =
1392+ !template_param_infos.GetParameterPack ().IsEmpty ()
1393+ ? GetValueParamType (template_param_infos.GetParameterPack ().Front ())
1394+ : QualType ();
1395+ if (!template_param_type.isNull ()) {
13871396 template_param_decls.push_back (NonTypeTemplateParmDecl::Create (
13881397 ast, decl_context, SourceLocation (), SourceLocation (), depth,
13891398 num_template_params, identifier_info, template_param_type,
@@ -1458,10 +1467,12 @@ static bool TemplateParameterAllowsValue(NamedDecl *param,
14581467 } else if (auto *type_param =
14591468 llvm::dyn_cast<NonTypeTemplateParmDecl>(param)) {
14601469 // Compare the argument kind, i.e. ensure that <typename> != <int>.
1461- if (!IsValueParam (value))
1470+ QualType value_param_type = GetValueParamType (value);
1471+ if (value_param_type.isNull ())
14621472 return false ;
1473+
14631474 // Compare the integral type, i.e. ensure that <int> != <char>.
1464- if (type_param->getType () != value. getIntegralType () )
1475+ if (type_param->getType () != value_param_type )
14651476 return false ;
14661477 } else {
14671478 // There is no way to create other parameter decls at the moment, so we
@@ -7351,10 +7362,27 @@ TypeSystemClang::GetIntegralTemplateArgument(lldb::opaque_compiler_type_t type,
73517362 return std::nullopt ;
73527363
73537364 const auto *arg = GetNthTemplateArgument (template_decl, idx, expand_pack);
7354- if (!arg || arg-> getKind () != clang::TemplateArgument::Integral )
7365+ if (!arg)
73557366 return std::nullopt ;
73567367
7357- return {{arg->getAsIntegral (), GetType (arg->getIntegralType ())}};
7368+ switch (arg->getKind ()) {
7369+ case clang::TemplateArgument::Integral:
7370+ return {{arg->getAsIntegral (), GetType (arg->getIntegralType ())}};
7371+ case clang::TemplateArgument::StructuralValue: {
7372+ clang::APValue value = arg->getAsStructuralValue ();
7373+ CompilerType type = GetType (arg->getStructuralValueType ());
7374+
7375+ if (value.isFloat ())
7376+ return {{value.getFloat (), type}};
7377+
7378+ if (value.isInt ())
7379+ return {{value.getInt (), type}};
7380+
7381+ return std::nullopt ;
7382+ }
7383+ default :
7384+ return std::nullopt ;
7385+ }
73587386}
73597387
73607388CompilerType TypeSystemClang::GetTypeForFormatters (void *type) {
0 commit comments