A function returns a lambda that captures its locals or parameters by reference, which dangle once it returns

tx0/cpp:lambda-returned-with-reference-capturesrecommendedwarningreliability/memory-safetydepth fastbug, cwe-562

What it finds

A lambda that captures by reference keeps references to the variables of the function that made it; returned from that function, it refers to objects that no longer exist. Capturing by value, or by move, keeps the values alive with the lambda.

From the rule's source, lambda_returned_with_reference_captures.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:lambda-returned-with-reference-captures" = "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:lambda-returned-with-reference-captures] reason="..."

tx0 explain tx0/cpp:lambda-returned-with-reference-captures shows the same in the terminal. Found a false positive? Report it.