[Bug c++/93480] Defaulted <=> doesn't expand array elements

2022-12-26 Thread rhalbersma at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

--- Comment #9 from rhalbersma  ---
Could this fix also be back-ported to gcc 10?

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2022-12-26 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |11.0

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2021-04-22 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Patrick Palka  changed:

   What|Removed |Added

 CC||rhalbersma at gmail dot com

--- Comment #8 from Patrick Palka  ---
*** Bug 94924 has been marked as a duplicate of this bug. ***

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2021-01-18 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Patrick Palka  changed:

   What|Removed |Added

 CC||vermaelen.wouter at gmail dot 
com

--- Comment #7 from Patrick Palka  ---
*** Bug 95608 has been marked as a duplicate of this bug. ***

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-22 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Jakub Jelinek  ---
Fixed for GCC 11.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-22 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

--- Comment #5 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:ffd454b92ba6ff5499cf57f82a2b0f4cee59978c

commit r11-6305-gffd454b92ba6ff5499cf57f82a2b0f4cee59978c
Author: Jakub Jelinek 
Date:   Tue Dec 22 20:18:10 2020 +0100

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  

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.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-21 Thread wjwray at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

--- Comment #4 from Will Wray  ---
Thanks Jakub;

I applied your patch to trunk and ran more test cases for
nested arrays (including zero-size in various positions),
union element type, base classes - all passed as expected.
I tried to grok the patch to look for problems - saw none.

In testing, a worse bug surfaced with defaulted operator==

The current bug was that defaulted <=> was deleted in the
presence of array members, so rel-ops fail to compile.

However, defaulted == is defined (on trunk) for array members
but appears to compare the pointer value of the decayed array
so == or != comparisons compile and give the wrong result
https://godbolt.org/z/Pbr9xr

Your patch fixes this bug also.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-20 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Jakub Jelinek  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #3 from Jakub Jelinek  ---
Created attachment 49810
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49810=edit
gcc11-pr93480.patch

Untested fix.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-19 Thread wjwray at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

--- Comment #2 from Will Wray  ---
For reference, here's a macro-free workaround to provide portable
operator<=> for templated classes with array members, defaulting
where possible (current Clang and MSVC) otherwise dispatching to
a user-defined implementation (current gcc)
https://godbolt.org/z/qbEfh7

First, a trait to check default 3-way array compare:

inline constexpr bool has_default_array_compare = [] {
struct C {
char c[1];
auto operator<=>(C const&) const = default;
};
return std::three_way_comparable;
}();

Then constrain the operator<=> definitions

template  struct array
{
T data[N];

friend auto operator<=>(array const&, array const&)
requires has_default_array_compare = default;

friend constexpr auto operator<=>(array const& l,
  array const& r)
requires (!has_default_array_compare)
{
return compare_three_way{}(l.data,r.data);
}
};

However, this only works for templated classes
as it is not (yet) allowed to constrain non-template functions.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-12-18 Thread wjwray at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Will Wray  changed:

   What|Removed |Added

 CC||wjwray at gmail dot com

--- Comment #1 from Will Wray  ---
I'm keen to see this fixed (and open to contribute)
(defaulted array comparison now works on Clang & MSVC).

Workaround for lack of compiler-generated array<=>array
is awkward and brittle: https://godbolt.org/z/xr668E

 * Preprocessor conditional compilation is required
   (at least there seems no way to detect array<=>array
support and dispatch to a user-defined comparison
only as needed - iff array members are present):

# if ! defined(__GNUC__) || defined(__clang__)
auto operator<=>(C const&) const = default;
# else
constexpr auto operator<=>(C const& r) const {
return three_way_compare(x,r.x);
}
#endif

Then:
 * A generic 3-way comparison for array should be recursive.
 * Achieving efficient/vector codegen is not straightforward.
 * Deducing the return type is subtle:

template 
constexpr auto three_way_compare(E const()[N],
 E const()[N]) {
auto c = l[0] <=> r[0];
for (int i = 0; ++i != N; c = l[i] <=> r[i])
if (c != 0)
return c;
return c;
}

So it'd be better for all if this were compiler-generated.

[Bug c++/93480] Defaulted <=> doesn't expand array elements

2020-01-28 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93480

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||rejects-valid
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-01-28
 Ever confirmed|0   |1