-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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: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
This issue is identified in #112751.
// case1
namespace std {
template<typename T>
struct unique_ptr {
T &operator*();
T *get() const [[clang::lifetimebound]];
};
} // namespace std
struct X {
X(std::unique_ptr<int> up) :
pointer(up.get()), owner(std::move(up)) {}
int *pointer;
std::unique_ptr<int> owner;
};
When we add the clang::lifetimebound
annotation to unique_ptr::get()
, clang emits a dangling-field warning for the pointer(up.get())
member initializer. This warning is a false positive in this context, as the owner
member is moved as part of the initialization, retaining ownership.
Another example occurs in designated-initializer cases:
// case2
struct X {
int *pointer;
std::unique_ptr<int> owner;
};
X func(std::unique_ptr<int> up) {
return {
.pointer = up.get(),
.owner = std::move(up)
};
}
Fixing these false positives is hard because it would require tracking dependencies between expressions, which is beyond the capabilities of the current statement-local analysis.
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: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