[libcxx-commits] [libcxx] Add [[clang::lifetimebound]] to numerous functions in libc++ include headers (PR #112751)

Gábor Horváth via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 22 07:25:52 PDT 2024


Xazax-hun wrote:

> Could we move the inference of those attributes from being hardcoded in clang to the library?

I believe the reason for the inference to be in the compiler so Clang can emit these diagnostics for other standard library implementations like libstdc++ and Microsoft's implementation. 

I think there is some value in detecting common cases if dangling on all platforms with all standard library implementations (I believe clang might default to non-libc++ standard libraries on some platforms).

That being said, I definitely think it makes sense to annotate the libraries, but I also think there is value in trying to make these diagnostics work for a wide range of our users.  Alternatively, I could imagine Clang shipping an APINotes file for the standard libraries and loading lifetimebound annotations from that file in case the library is not annotated. 

> I'd like to better understand what are the benefits of doing that 

Some example diagnostics are here: https://github.com/llvm/llvm-project/blob/main/clang/test/SemaCXX/attr-lifetimebound.cpp


https://github.com/llvm/llvm-project/pull/112751


More information about the libcxx-commits mailing list