Skip to content

[LifetimeSafety] False-negative for 'this' param annotated in declaration but not in definition #172013

@usx95

Description

@usx95

https://godbolt.org/z/GerTP67dc

#include <string>
#include <string_view>

struct S {
    std::string_view x() const [[clang::lifetimebound]];
    std::string i;
};

std::string_view S::x() const { return i; }

void G() {
    std::string_view x;
    {
        S s;
        x = s.x(); // No error. Bad.
    }
    (void)x;
}

std::string_view LB(std::string_view in [[clang::lifetimebound]]);

std::string_view LB(std::string_view in) { return in; }

void foo() {
    std::string_view x;
    {
        std::string s;
        x = s; // Error! Good.
    }
    (void)x;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions