Skip to content

missing dangling reference warnings if lifetimebound is applied to a function declaration but not the definition #62072

@zygoloid

Description

@zygoloid

Testcase:

struct S {
    const int& x() const [[clang::lifetimebound]];
    static const int& y(const S &self [[clang::lifetimebound]]);
    int i;
};

#if DO_INLINE
inline const int& S::x() const { return i; }
inline const int& S::y(const S &self) { return self.i; }
#endif

void G() {
    auto& x = S().x();
    auto& y = S::y(S());
}

Clang warns that x and y are dangling with -UDO_INLINE but the warnings are silenced under -DDO_INLINE. It looks like these attributes are not being propagated from the declaration to the definition properly (presumably because they are type attributes rather than declaration attributes, and they don't change the canonical type).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang: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