llvm / llvm/llvm-project

[[clang::lifetimebound]] triggers a spurious Wdangling-assignment

Open
#189,965 1 comment 0 reactions 0 assignees View on GitHub
clang:temporal-safety false-positive
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Observed this with `ABSL_CHECK_OK` after adding auto-suggested `lifetimebound` annotations to `AsStatus()`, but a simplified example is:

```c++
const int* Ptr(const int& x [[clang::lifetimebound]]) {
return &x;
}

int main() {
for (const int* p; p = Ptr(42), p != nullptr; )
// ^^^ warning: object backing the pointer 'p' will be destroyed at the end of the full-expression [-Wdangling-assignment]
break;
}
```
https://godbolt.org/z/4zr9szjoq

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.