It appears that the default op== for a C-array has array-to-pointer decay applied and does not compare the underlying array data. struct S { int data[1]; bool operator==(const S&) const = default; }; int main() { static_assert(S{1} != S{1}); constexpr auto s = S{1}; static_assert(s == s); } Tested on tip-of-trunk at Wandbox: https://wandbox.org/permlink/YxUv5dFs7mSGlNBx Works correctly on Clang >= 10.
I just became aware of [depr.array.comp] in N4861 "Equality and relational comparisons (7.6.10, 7.6.9) between two operands of array type are deprecated." This is very surprising to say the least and disqualifies default op= for any class containing a C-array. But in any case, should such code generate a warning message? And this bug be closed?
OK, Alisdair Meredith points out on Twitter that in [class.compare.default]/6 there is a special sentence on array class data members In that list, any subobject of array type is recursively expanded to the sequence of its elements, in the order of increasing subscript. So only direct array comparisons are deprecated.
Looks like a dup of PR93480, which has been fixed for GCC 11. *** This bug has been marked as a duplicate of bug 93480 ***
Is there any chance that this bug fix can be backported to gcc 10 also?