[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
Tue Aug 20 07:03:44 PDT 2024


================
@@ -169,14 +169,14 @@ def note_constexpr_this : Note<
 def access_kind : TextSubstitution<
   "%select{read of|read of|assignment to|increment of|decrement of|"
   "member call on|dynamic_cast of|typeid applied to|construction of|"
-  "destruction of}0">;
+  "destruction of|read of}0">;
 def access_kind_subobject : TextSubstitution<
   "%select{read of|read of|assignment to|increment of|decrement of|"
   "member call on|dynamic_cast of|typeid applied to|"
-  "construction of subobject of|destruction of}0">;
+  "construction of subobject of|destruction of|read of}0">;
----------------
MitalAshok wrote:

This is for the messages shown in places like this:

```c++
constexpr struct { mutable int i } s;
static_assert(__builtin_is_within_lifetime(&s.i));
// read of mutable member 'i' is not allowed in a constant expression
```

This is the same message as `AK_Read` and `AK_ReadObjectRepresentation` because `is_within_lifetime` has basically the same restrictions as reading the value of an object (you "read" the value just to check if it is in lifetime).

Open to other suggestions to make it more clear

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


More information about the cfe-commits mailing list