[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 06:53:33 PDT 2024


MitalAshok wrote:

The feature test macro (`__cpp_lib_is_within_lifetime`) should be defined by the standard library in `<type_traits>`/`<version>` (so libc++ or libstdc++).  
All that changes for Clang with this patch is `__has_builtin(__builtin_is_within_lifetime)`. P2641R4 doesn't appear to be in [cxx_status](https://clang.llvm.org/cxx_status.html). It's on the [libc++ C++26 status page](https://libcxx.llvm.org/Status/Cxx2c.html), which can be updated when this is exposed as `std::is_within_lifetime`.

I'll add VLA tests. I'm surprised they are available at all during constant evaluation. I will make it just error on VLA types, since those can't be passed to the template function `is_within_lifetime(const auto*)`. VLA objects will still be supported the same as any other object if they are used after being cast to `void*`.

I also don't think the current behaviour before/during constructors and during/after destructors is correct, and I have to add more tests (for basically every scenario in [basic.life]).


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


More information about the cfe-commits mailing list