Aviso C26815 o ponteiro é pendente porque aponta para uma instância temporária que foi destruída. (ES. 65)
Há um ponteiro pendente que é o resultado de um temporário sem nome que foi destruído.
Exemplo
std::optional<std::vector<int>> getTempOptVec();
void loop() {
// Oops, the std::optional value returned by getTempOptVec gets deleted
// because there is no reference to it.
for (auto i : *getTempOptVec()) // warning C26815
{
// do something interesting
}
}
void views()
{
// Oops, the 's' suffix turns the string literal into a temporary std::string.
std::string_view value("This is a std::string"s); // warning C26815
}
Esses avisos podem ser corrigidos estendendo o tempo de vida do objeto temporário.
std::optional<std::vector<int>> getTempOptVec();
void loop() {
// Fixed by extending the lifetime of the std::optional value by giving it a name.
auto temp = getTempOptVec();
for (auto i : *temp)
{
// do something interesting
}
}
void views()
{
// Fixed by changing to a constant string literal.
std::string_view value("This is a string literal");
}