A reference is bound to the result of std::min, std::max or std::clamp with a temporary argument
What it finds
const int &limit = std::min(size, n + 1);: std::min, std::max and std::clamp return a reference to one of their arguments. When that argument is a temporary, as n + 1 or a literal, it is destroyed at the end of the declaration, and the reference dangles from the next statement on; reading it is undefined.
``cpp const int &limit = std::max(count, 16); use(limit); // 16 no longer exists ``
Declaring the variable as a value, const int limit = std::max(count, 16);, keeps a copy. The rule reports references, & or &&, initialized by such a call with a literal, an arithmetic expression or a functional cast among the arguments.
From the rule's source, reference_to_temporary_from_min_max.rs.
Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/cpp:reference-to-temporary-from-min-max" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/cpp:reference-to-temporary-from-min-max] reason="..."tx0 explain tx0/cpp:reference-to-temporary-from-min-max shows the same in the terminal. Found a false positive? Report it.