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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 1 05:19:08 PDT 2024


AaronBallman wrote:

> As I've just commented at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114479 the `__is_array` intrinsic exists to optimize `std::is_array` and so should match its existing behaviour. If you want to change the behaviour of `std::is_array` then please do so via an LWG issue, e.g. requesting clarification of the behaviour for `T[0]`.
> 
> An optimization to speed up compilation of `std::is_array` should not dictate its behaviour.

Errr, I think there's some circular logic here perhaps:

> [dcl.array] says that for T[N] the value "N specifies the array bound, i.e., the
number of elements in the array; N shall be greater than zero."
>
> So T[0] is not a valid array type.

Except `T[0]` is a valid array type because it's supported as a language extension in Clang and GCC; that's the whole reason you can spell `T[0]` at all.

This boils down to a fundamental question: what makes something an array type in the first place? Is it the declaration syntax or is it the semantics? If it's declaration syntax, then `T[0]` is clearly an array type. If it's semantics, then `T[0]` is not an array type but `std::vector<int>` is. Personally, I think the declaration syntax is what makes something an array type per https://eel.is/c++draft/dcl.array#1 saying "a declaration of the form". Yes, it says the size shall not be zero, but that's the bit we've extended, so it's circular to say "the standard says zero isn't allowed and therefore the library behavior is to return false from std::is_array".

So I think I'm arguing for an LWG issue.

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


More information about the cfe-commits mailing list