-Wdangling-gsl only warns on initialization and not on assignment #46984
Labels
bugzilla
Issues migrated from bugzilla
clang:diagnostics
New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
duplicate
Resolved as duplicate
Extended Description
-Wdangling-gsl is a warning that catches dangling pointers. This warning catches a lot of lifetime bugs, but it only does so during initialization. Similar code that causes a dangling pointer during assignments does not get a warning.
#include
#include <string_view>
#include
std::string get_string();
std::unique_ptr get_int();
int main() {
std::string_view sv = get_string(); // Warning on initialization
sv = get_string(); // No warning on assignment
int *p = get_int().get(); // Warning on initialization
p = get_int().get(); // No warning on assignment
}
The text was updated successfully, but these errors were encountered: