Given the code below.
Are we correct to assume this is a FP detection and we can safely disable the warning or not?
We assume it is a false positive as the result of std::to_string(int)
will exists on the stack till the function call is over, but of course we want to be sure ...
// Definition of the function to be called
void my_function(const std::vector<std::string_view>& args) {}
// The function call complaining
my_function({
std::to_string(10) //error C26449: gsl::span or std::string_view created from a temporary will be invalid when the temporary is invalidated
});
// Of course we could write the code like this, but yeah we would like to know the theory and prefer the less bulk notation :)
auto var = std::to_string(10);
my_function({
var
});
It all comes down to when will the std::string
from std::to_string
will be disposed.