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

[LifetimeSafety] Diagnose redeclarations in a different file whose lifetimebound annotations differ from the canonical declaration

Open NeKon69 opened this issue 6 months ago • 4 comments

After #197753, we decided that users should be asked to annotate the canonical declaration.

However, if a redeclaration is in a different file from the canonical declaration, and that redeclaration does not have a lifetimebound attribute that is present on the canonical declaration, we should diagnose that redeclaration as well.

// header.h
int* foo(int& x); // warning: redeclaration of function 'foo' does not have a 'lifetimebound' attribute on parameter 'x'
// source.cpp
int* foo(int& x [[clang::lifetimebound]]);

#include "header.h"

int* foo(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 established that it would be beneficial if we would warn on all redeclarations without the attribute. It would be something like: ```cpp int* foo(int& x [[clang::lifetimebound]]);

int* foo(int& x); // redeclaration of a function 'foo' does not have a 'lifetimebound' attribute on parameter 'x'

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

</details>

I am not in favour of this. I think we decided that we should ask users to annotate the canonical declaration.

But if we see a redecl in a header file which is not the canonical decl and is not in the same file as the canonical decl then we should ask users to annotate this redecl as well. Did you want to capture this part of the discussion ?

usx95 avatar May 20 '26 12:05 usx95

Yeah that makes more sense to me, thanks for the correction.

NeKon69 avatar May 20 '26 12:05 NeKon69

I would like to work on this.

NeKon69 avatar May 21 '26 12:05 NeKon69