Skip to content

[LifetimeSafety] Add fix-its for misplaced lifetimebound diagnostics #198634

@NeKon69

Description

@NeKon69

After #197753, we now warn when lifetimebound is written on the wrong declaration. This diagnostic would ideally have a fix-it that adds the attribute to the declaration that should carry it.

Currently we only warn that the user should add a lifetimebound attribute:

int* get(int &x); // warning: 'lifetimebound' attribute on this definition is not visible to callers before the definition; add it to the declaration instead

int* get(int &x [[clang::lifetimebound]]) {
  return &x;
}

It would be more user-friendly if we could also create a suggestion with a lifetimebound attribute:

int* get(int &x); // fix-it: add [[clang::lifetimebound]] here

int* get(int &x [[clang::lifetimebound]]) {
  return &x;
}

After applying the fix-it:

int* get(int &x [[clang::lifetimebound]]);

int* get(int &x [[clang::lifetimebound]]) {
  return &x;
}

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 fields configured for Task.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions