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

Diagnose [[clang::lifetimebound]] on functions whose return value cannot refer to any object

Open aeft opened this issue 8 months ago • 2 comments

[[clang::lifetimebound]] on a parameter is meaningful only when the function's return value can refer to another object. When the return type is something like int or an enum, the returned value cannot carry a borrow, and the attribute has no effect:

int getInt(const std::string &s [[clang::lifetimebound]]);

We should emit a diagnostic for this case.

cc @usx95

aeft avatar Mar 26 '26 01:03 aeft

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

Author: Zhijie Wang (aeft)

`[[clang::lifetimebound]]` on a parameter is meaningful only when the function's return value can refer to another object. When the return type is something like `int` or an enum, the returned value cannot carry a borrow, and the attribute has no effect:
int getInt(const std::string &s [[clang::lifetimebound]]);

We should emit a diagnostic for this case.

cc @usx95

llvmbot avatar Mar 26 '26 01:03 llvmbot

I would like to work on this.

NeKon69 avatar Jun 14 '26 11:06 NeKon69