llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LifetimeSafety] Add fix-its for misplaced lifetimebound diagnostics

Open NeKon69 opened this issue 6 months ago • 4 comments

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;
}

NeKon69 avatar May 19 '26 20:05 NeKon69

@llvm/issue-subscribers-clang-temporal-safety

Author: 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.
int* get(int &x); // should suggest adding lifetimebound here 
int* get(int &x [[clang::lifetimebound]]) {
  return &x;
}

Can you please add a more elaborate example of what is the current vs the expected behaviour

usx95 avatar May 20 '26 12:05 usx95

Done

NeKon69 avatar May 20 '26 12:05 NeKon69

I will give this a try

davidmenggx avatar May 21 '26 17:05 davidmenggx