| Issue |
176144
|
| Summary |
Detect dangling references to field members
|
| Labels |
clang:temporal-safety
|
| Assignees |
|
| Reporter |
usx95
|
```cpp
#include <string>
#include <string_view>
template<class... T> void use(T... arg);
struct S {
std::string_view sv;
std::string s;
};
struct Q {
const S* get() const [[clang::lifetimebound]];
};
std::string_view foo(std::string_view sv [[clang::lifetimebound]]);
void test1() {
std::string_view k1 = S().sv; // OK
std::string_view k2 = S().s; // expected-warning {{object backing the pointer will}}
std::string_view k3 = Q().get()->sv; // OK
std::string_view k4 = Q().get()->s; // expected-warning {{object backing the pointer will}}
std::string_view lb1 = foo(S().s); // expected-warning {{object backing the pointer will}}
std::string_view lb2 = foo(Q().get()->s); // expected-warning {{object backing the pointer will}}
use(k1, k2, k3, k4, lb1, lb2);
}
```
None of the expected-warnings fire for lifetime safety analysis.
https://godbolt.org/z/fcznTvWfK
(The examples include only temporaries but this is not particular to temporaries).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs