[clang] [Clang] Fix __is_array returning true for zero-sized arrays (PR #86652)

Nikolas Klauser via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 26 06:05:03 PDT 2024


philnik777 wrote:

> > According to the spec it's ill-formed, so I'm not sure it falls under any sensible category.
> 
> It's an extension we support so it's up to us to decide what sensible is.

Sure. If we end up putting it in the array category we should probably coordinate with GCC.

> > For T[0] this returns false.
> 
> Understood, but why is this not the bug to be fixed? (It would also fix the `takes_an_array` case as well.)

Because I don't think we can. AFAICT this is valid C++:
```c++
template <unsigned Size, class = int[Size]>
int func() {
  return 1;
}

template <unsigned Size>
int func() {
  return 0;
}
```
If clang accepted `int[0]` in this context the observable behaviour would change.

> > We don't use the trait currently in libc++ because of this bug and GCC only added it in trunk (and have the same bug), so probably not.
> 
> For example, it seems to be used in Unreal Engine: https://github.com/windystrife/UnrealEngine_NVIDIAGameWorks/blob/b50e6338a7c5b26374d66306ebc7807541ff815e/Engine/Source/Runtime/Core/Public/Templates/UnrealTemplate.h#L128

If you think it's a significant enough change that we should add an ABI tag I can do that.


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


More information about the cfe-commits mailing list