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

-Wlifetime-safety-suggestions fixit misplaced to default argument

Open emaxx-google opened this issue 7 months ago • 3 comments

Input:

int* f(int* x = nullptr) {
  return x;
}

Command:

$ clang++ -Wlifetime-safety -Wlifetime-safety-suggestions -Xclang -fixit main.cc
main.cc:1:8: warning: parameter in intra-TU function should be marked [[clang::lifetimebound]] [-Wlifetime-safety-intra-tu-suggestions]
    1 | int* f(int* x = nullptr) {
      |        ^~~~~~~~~~~~~~~~
      |                         [[clang::lifetimebound]]
main.cc:1:8: note: FIX-IT applied suggested code changes

Result:

int* f(int* x = nullptr [[clang::lifetimebound]]) {
  return x;
}

Double-checking:

$ clang++ main.cc
main.cc:1:25: error: an attribute list cannot appear here
    1 | int* f(int* x = nullptr [[clang::lifetimebound]]) {
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

emaxx-google avatar Apr 15 '26 14:04 emaxx-google

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

Author: Maksim Ivanov (emaxx-google)

Input:
int* f(int* x = nullptr) {
  return x;
}

Command:

$ clang++ -Wlifetime-safety -Wlifetime-safety-suggestions -Xclang -fixit main.cc
main.cc:1:8: warning: parameter in intra-TU function should be marked [[clang::lifetimebound]] [-Wlifetime-safety-intra-tu-suggestions]
    1 | int* f(int* x = nullptr) {
      |        ^~~~~~~~~~~~~~~~
      |                         [[clang::lifetimebound]]
main.cc:1:8: note: FIX-IT applied suggested code changes

Result:

int* f(int* x = nullptr [[clang::lifetimebound]]) {
  return x;
}

Double-checking:

$ clang++ main.cc
main.cc:1:25: error: an attribute list cannot appear here
    1 | int* f(int* x = nullptr [[clang::lifetimebound]]) {
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

llvmbot avatar Apr 15 '26 14:04 llvmbot

I will work on this.

NeKon69 avatar May 15 '26 20:05 NeKon69

thanks a lot!

emaxx-google avatar May 18 '26 09:05 emaxx-google