Attribute clang::lifetimebound produces no warning when assign temporary's address to pointer declared before. (original) (raw)
[[clang::lifetimebound]] could be used to provide some lifetime annotation to functions. In the statement of a pointer initialization, everything works fine. But in the statement of a pointer assignment, the desired warning can not be produced.
Here is the code sample:
#include
const char* get(const std::string& s [[clang::lifetimebound]]){ return s.data(); }
int main(){ // can be detected const char* s1 = get("hello"s);
// cannot be detected const char* s2 = nullptr; s2 = get("hello"s);
return 0; }
Here is more code to illustrate this: https://godbolt.org/z/fhTPYTa1d
Is this intentional or a flaw of lifetime check?