diff --git a/AK/Array.h b/AK/Array.h index 26c0a225b50..3bb11998a37 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -13,6 +13,16 @@ namespace AK { +namespace Detail { +// This type serves as the storage of 0-sized `AK::Array`s. While zero-length `T[0]` +// is accepted as a GNU extension, it causes problems with UBSan in Clang 16. +template +struct EmptyArrayStorage { + T& operator[](size_t) const { VERIFY_NOT_REACHED(); } + constexpr operator T*() const { return nullptr; } +}; +} + template struct Array { using ValueType = T; @@ -109,7 +119,7 @@ struct Array { return value; } - T __data[Size]; + Conditional, T[Size]> __data; }; template