From 7743dcf4a971a00aa56f392bfe7b882d30183d4b Mon Sep 17 00:00:00 2001 From: 0x4261756D <38735823+0x4261756D@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:11:35 +0200 Subject: [PATCH] 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. --- Meta/Lagom/Tools/LibJSGCVerifier/src/CellsHandler.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Meta/Lagom/Tools/LibJSGCVerifier/src/CellsHandler.cpp b/Meta/Lagom/Tools/LibJSGCVerifier/src/CellsHandler.cpp index f2febcf9399..fb6cb0a6bd4 100644 --- a/Meta/Lagom/Tools/LibJSGCVerifier/src/CellsHandler.cpp +++ b/Meta/Lagom/Tools/LibJSGCVerifier/src/CellsHandler.cpp @@ -90,8 +90,9 @@ std::vector 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(); if (!record_type) return result;