Skip to content

Add implicit lifetimebound annotations to std::make_unique #164259

@usx95

Description

@usx95

Consider this definition of std::make_unique:

template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

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

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<A> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions