llvm / llvm/llvm-project

[LifetimeSafety] Inference/suggest `lifetimebound` with `make_unique` / `std::make_shared` / `unique_ptr(new T)` / `shared_ptr(new T)`

Open
#198,478 2 comments 0 reactions 0 assignees View on GitHub
clang:temporal-safety false-negative
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/cc81oTzjW

```cpp
#include

struct Foo {
Foo(int* p [[clang::lifetimebound]]) : p(p) {}
int* p;
};

// lifetimebound suggestion triggered, good.
auto f1(int* p) -> Foo
{
return Foo(p);
}

// lifetimebound suggestion not triggered, bad.
auto f2(int* p) -> std::unique_ptr
{
return std::make_unique(p);
}

// lifetimebound suggestion not triggered, bad.
auto f3(int* p) -> std::shared_ptr
{
return std::make_shared(p);
}

// lifetimebound suggestion not triggered, bad.
auto f4(int* p) -> std::unique_ptr
{
return std::unique_ptr(new Foo(p));
}

// lifetimebound suggestion not triggered, bad.
auto f5(int* p) -> std::shared_ptr
{
return std::shared_ptr(new Foo(p));
}
```

`-Wlifetime-safety-all -Xclang=-flifetime-safety-inference`

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.