LibJSGCVerifier: Fix dangling-reference errors

When building, clang would throw errors about dangling references.
Extracting `template_args` to a variable before the loop and
indexing into that seems to fix the errors.
This commit is contained in:
0x4261756D 2024-04-03 15:11:35 +02:00 committed by Andreas Kling
parent bf722d49b0
commit 7743dcf4a9
Notes: sideshowbarker 2024-07-17 06:29:49 +09:00

View file

@ -90,8 +90,9 @@ std::vector<clang::QualType> get_all_qualified_types(clang::QualType const& type
if (specialization_name == "JS::GCPtr" || specialization_name == "JS::NonnullGCPtr") {
qualified_types.push_back(type);
} else {
for (size_t i = 0; i < template_specialization->template_arguments().size(); i++) {
auto const& template_arg = template_specialization->template_arguments()[i];
auto const template_arguments = template_specialization->template_arguments();
for (size_t i = 0; i < template_arguments.size(); i++) {
auto const& template_arg = template_arguments[i];
if (template_arg.getKind() == clang::TemplateArgument::Type) {
auto template_qualified_types = get_all_qualified_types(template_arg.getAsType());
std::move(template_qualified_types.begin(), template_qualified_types.end(), std::back_inserter(qualified_types));
@ -143,10 +144,11 @@ FieldValidationResult validate_field(clang::FieldDecl const* field_decl)
if (template_type_name != "GCPtr" && template_type_name != "NonnullGCPtr")
return result;
if (specialization->template_arguments().size() != 1)
auto const template_args = specialization->template_arguments();
if (template_args.size() != 1)
return result; // Not really valid, but will produce a compilation error anyway
auto const& type_arg = specialization->template_arguments()[0];
auto const& type_arg = template_args[0];
auto const* record_type = type_arg.getAsType()->getAs<clang::RecordType>();
if (!record_type)
return result;