Skip to content

Commit

Permalink
Avoid false positives from GCC's new dangling reference warnings. (#17)
Browse files Browse the repository at this point in the history
Though there was nothing wrong with the previous code - the temporary is only
used throughout its lifetime and isn't even returned - this change is the
easiest way to shut up GCC so that we have a chance of detecting real problems.
  • Loading branch information
LTLA authored Feb 5, 2025
1 parent affaa00 commit d26fb7e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/uzuki2/parse_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals& e
}
}

const auto& lvals = extract_array(map, "levels", path);
const std::string levels_name = "levels"; // avoid dangling reference from casting of string literal.
const auto& lvals = extract_array(map, levels_name, path);
int32_t nlevels = lvals.size();
auto fptr = process_array_or_scalar_values(map, path, [&](const auto& vals, bool named, bool scalar) -> auto {
auto ptr = Provisioner::new_Factor(vals.size(), named, scalar, nlevels, ordered);
Expand Down Expand Up @@ -365,7 +366,8 @@ std::shared_ptr<Base> parse_object(const millijson::Base* contents, Externals& e
auto names_ptr = has_names(map, path);
bool has_names = names_ptr != NULL;

const auto& vals = extract_array(map, "values", path);
const std::string values_name = "values"; // avoid dangling reference from casting of string literal.
const auto& vals = extract_array(map, values_name, path);
auto ptr = Provisioner::new_List(vals.size(), has_names);
output.reset(ptr);

Expand Down

0 comments on commit d26fb7e

Please sign in to comment.