Skip to content

Support lifetimebound calls where return type is not a pointer/view type #163600

@usx95

Description

@usx95
#include <iostream>
#include <string>
#include <string_view>

struct S {
    std::string_view data;
};

S getS(const std::string& s [[clang::lifetimebound]]) { return S{s}; }

void foo() {
    S s;
    {
        std::string str = "small scoped string";
        s = getS(str);
    }
    std::cout << s.data; // use-after-free
}

https://godbolt.org/z/9s1xqc3nW

Metadata

Metadata

Assignees

Labels

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

Type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions