Skip to content

[clang][LifetimeSafety] False finding for loan in a loop #156959

@usx95

Description

@usx95
struct MyObj {
    int id;
    ~MyObj() {}
};

void foo(bool cond) {
    MyObj b;
    for (; cond;) {
        MyObj a;
        MyObj* p = &b;
        if (cond) {
            p = &a; //  error: object whose reference is captured may not live long enough. <Bad!>
        }
        (void)*p; // note: later used here.
    } // note: destroyed here.
}

https://godbolt.org/z/Y176hhx9q

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)false-positiveWarning fires when it should not

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions