c++: Handle array members in build_comparison_op [PR93480]
authorJakub Jelinek <jakub@redhat.com>
Tue, 22 Dec 2020 19:18:10 +0000 (20:18 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 22 Dec 2020 19:18:10 +0000 (20:18 +0100)
commitffd454b92ba6ff5499cf57f82a2b0f4cee59978c
tree8e9be7258613548484c6d7e387cea7c9c66b4862
parentae27ce51e4860388d2b4129e2a80cc7f292368b5
c++: Handle array members in build_comparison_op [PR93480]

http://eel.is/c++draft/class.compare.default#6 says for the
expanded list of subobjects:
"In that list, any subobject of array type is recursively expanded
to the sequence of its elements, in the order of increasing subscript."
but build_comparison_op just tried to compare the whole arrays, which
failed and therefore the defaulted comparison was deleted.

The following patch instead compares the array elements, and
if info.defining, adds runtime loops around it so that it iterates
over increasing subscripts.

For flexible array members it punts, we don't know how large those will be,
for zero sized arrays it doesn't even try to compare the elements,
because if there are no elements, there is nothing to compare, and
for [1] arrays it will not emit a loop because it is enough to use
[0] array ref to cover everything.

2020-12-21  Jakub Jelinek  <jakub@redhat.com>

PR c++/93480
* method.c (common_comparison_type): If comps[i] is a TREE_LIST,
use its TREE_VALUE instead.
(build_comparison_op): Handle array members.

* g++.dg/cpp2a/spaceship-synth10.C: New test.
* g++.dg/cpp2a/spaceship-synth-neg5.C: New test.
gcc/cp/method.c
gcc/testsuite/g++.dg/cpp2a/spaceship-synth-neg5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/spaceship-synth10.C [new file with mode: 0644]