Skip to content

[LifetimeSafety] False-positive for loan in a loop #156959

@usx95

Description

@usx95
struct MyObj { int id; ~MyObj() {} }; void foo(bool cond) { MyObj b; MyObj* p; for (; cond;) { MyObj a; 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

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions