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

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon May 19 16:55:02 PDT 2025


ahatanak wrote:

> 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.

But there isn't much we can do with unknown pointers or references, is there?

We can't have `foo` return 4 unless we know for sure that `s` isn't embedded in a larger object. In the following case, wouldn't `foo` be expected to return 12?

```
int bar() {
  S a[2];
  return foo(a[0]);
}
```

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


More information about the cfe-commits mailing list