[clang] [Clang] Implement P2280R4 Using unknown pointers and references in constant expressions (PR #95474)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon May 19 14:16:42 PDT 2025


zygoloid wrote:

> Should `foo` in the following code return 4 when `-fstrict-flex-arrays` is 2 or 3 (but not when it's 0 or 1) only when the target is `-std=c++23` or newer? Or should it return 4 for older standards too?

We evaluate the operand of `__builtin_object_size` in `EM_IgnoreSideEffects` mode, which is documented as:

> ```c++
> /// Evaluate in any way we know how. Don't worry about side-effects that
> /// can't be modeled.
> ```

If that mode doesn't already permit using unknown pointers and references in all language modes, then we should change it so that it does. `__builtin_object_size` is best-effort, but we should produce a constant value for it that's not the `-1` or `0` fallback value whenever we're able to do so.

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


More information about the cfe-commits mailing list