-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Open
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 analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)
Description
[[gsl::Pointer]] can be used to diagnose a limited set of dangling pointer issues. However, it does not seem to preserve lifetime info through copies; see https://godbolt.org/z/vfjojda7K. Since the docs say a class so annotated "behaves like a pointer into the owner", it seems like copied "pointer"s should also dangle when the original owner is destroyed.
#include <optional>
struct [[gsl::Owner]] T {};
struct [[gsl::Pointer]] S {
S(const T&);
};
S f1() {
T t;
return S(t); //-Wreturn-stack-address, yay
}
S f2() {
T t;
S s(t);
return s; // No -Wreturn-stack-address, boo
}
std::optional<S> f3() {
T t;
return S(t); // No -Wreturn-stack-address, boo
}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 analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)Issue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)
Type
Projects
Status
No status