A std::string_view is initialized from a temporary string, which is destroyed at the end of the statement

tx0/cpp:view-of-temporary-stringdefaulterrorreliability/memory-safetydepth fastbug, cwe-416

What it finds

std::string_view v = std::to_string(n); keeps a view of a temporary std::string that is destroyed when the declaration ends, so every later use of v reads freed memory. The string needs a variable of its own.

From the rule's source, view_of_temporary_string.rs.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:view-of-temporary-string" = "off"

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:view-of-temporary-string] reason="..."

tx0 explain tx0/cpp:view-of-temporary-string shows the same in the terminal. Found a false positive? Report it.