<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114201>114201</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dangling false positive if the the owner is also moved in the initializer.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:diagnostics,
clang:memory-safety
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hokein
</td>
</tr>
</table>
<pre>
This issue is identified in #112751.
```cpp
// 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:
```cpp
// 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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVd2O4jgTfRpzUwIlDuHnIhd0MzxBS1_ffXLsgtSOY2fsStPs06_sQDfMTo9GK5kQ2cdVp8rnOCpGOjnERtRPot7P1MidD03nvyO5WevNpXnpKALFOCKkF4OO6UhogBwIWZWlXNflQhR7Ueyuz1UxDT0M1xl5EPIAWkUspxmneoyD0giRDYj10zTN2A9WMYrqmS8DJhS8iOrbtBo5jJphdPRjxP8PHD43AryAkCs_YFDsg5A7ITdCbkX1ANidkKcF0N5Fhlz3k7bKnUS1E9XO0hGZemz96Iyo92ncYoj1wztcy3qo5b4RV76v9zRfhdwkWE72WYmonsmxqL7BOCR2aX3aMXhyjEHIz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