Issue 180512
Summary [LifetimeSafety] Move through return is not detected and gives false-positives
Labels false-positive, clang:temporal-safety
Assignees
Reporter usx95
    https://godbolt.org/z/Gacde56PP
```
#include <memory>

struct S {
    std::unique_ptr<int> createAndSet() {
 std::unique_ptr<int> up = std::make_unique<int>(0);
        p = up.get();
 return up;
    }
    int* p;
};
```
Warning:
```
<source>:6:13: warning: address of stack memory escapes to a field. This could be a false positive as the storage may have been moved. Consider moving first and then aliasing later to resolve the issue [-Wlifetime-safety-dangling-field-strict]
    6 |         p = up.get();
 |             ^~
<source>:7:16: note: potentially moved here
    7 | return up;
      |                ^~
<source>:9:10: note: this field dangles
    9 |     int* p;
      |          ^
```
Here the `unique_ptr` is returned by move and aliases to it should not be considered to be dangling
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to