Skip to content

Find a solution to annotate forwarding functions like std::make_unique #163602

@usx95

Description

@usx95
#include <iostream>
#include <memory>

struct A {
    std::string_view data;
    A(const std::string& a [[clang::lifetimebound]]) : data(a) {}
    std::string_view getData() { return data; }
};

std::unique_ptr<A> bar() {
    std::string on_stack = "I live on stack";
    std::unique_ptr<A> obj = std::make_unique<A>(on_stack);
    return obj; // return stack address of locak 'on_stack'
}

int main() {
    std::unique_ptr<A> obj = bar();
    std::cout << obj->getData();
}

https://godbolt.org/z/ozo5q4Wx1

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