llvm / llvm/llvm-project

Add implicit lifetimebound annotations to std::make_unique

Open
#164,259 2 comments 0 reactions 1 assignee Claimed by @usx95 View on GitHub
clang:temporal-safety
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider this definition of `std::make_unique`:

```cpp
template
std::unique_ptr make_unique(Args&&... args) {
return std::unique_ptr(new T(std::forward(args)...));
}
```

Add implicit annotations to the template instantiations of `make_unqiue` where the constructed type has `lifetimebound` arguments.

```cpp
struct A {
std::string_view view;
std::string owner;
A(const std::string& a [[clang::lifetimebound]], const std::string& b) : view(a), owner(b) {}
};
```
`std::make_unique` function template should have its first arg to `a` as `lifetimebound` but not the other other arg to `b`.
This can be done by looking at the corresponding constructor of the type being constructed. [example](https://github.com/google/crubit/blob/29690a31672dbc54108ee70cb65fe22570eb1356/nullability/pointer_nullability_diagnosis.cc#L683)

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.