-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Description
Currently, -Wdangling
/-Wdangling-gsl
detect the following:
std::string foo() { return ""; }
int main() {
std::string_view v = foo(); // error: object backing the pointer will be destroyed at the end of the full-expression [-Werror,-Wdangling-gsl]
}
However, they fail to detect this case:
std::string foo() { return ""; }
int main() {
std::string_view v;
v = foo(); // no error
}
It seems the compiler currently only handles initializations, not regular assignments, despite them posing the same issue. So it would be great to handle the second case as well.
More generally, if a lifetimebound
object is assigned to a non-temporary expression, then I believe it would be correct to issue the diagnostic.
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer