| Issue |
203839
|
| Summary |
[LifetimeSafety] suggested `[[clang::lifetimebound]]` results in violation
|
| Labels |
clang:diagnostics,
clang:temporal-safety
|
| Assignees |
|
| Reporter |
firewave
|
```cpp
#include <cstdint>
#include <cstring>
#define LIFETIMEBOUND
struct View
{
View(const char* data LIFETIMEBOUND)
: mData(data)
, mSize(strlen(data))
{}
const char* data() const {
return mData;
}
std::size_t size() const {
return mSize;
}
private:
const char* mData;
std::size_t mSize;
};
```
```
<source>:8:10: warning: parameter in intra-TU function should be marked [[clang::lifetimebound]] [-Wlifetime-safety-intra-tu-suggestions]
8 | View(const char* data LIFETIMEBOUND)
| ^~~~~~~~~~~~~~~~
| [[clang::lifetimebound]]
<source>:22:17: note: escapes to this field
22 | const char* mData;
| ~~~~~~~~~~~~^~~~~
```
https://godbolt.org/z/3Gc7nY4o4
If you fix that warning it leads to
```
<source>:8:27: warning: could not verify that the return value can be lifetime bound to 'data' [-Wlifetime-safety-lifetimebound-violation]
8 | View(const char* data LIFETIMEBOUND)
| ^~~~~~~~~~~~~
<source>:4:25: note: expanded from macro 'LIFETIMEBOUND'
4 | #define LIFETIMEBOUND [[clang::lifetimebound]]
| ^~~~~~~~~~~~~~~~~~~~
```
https://godbolt.org/z/PK3WK433G
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs