[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2024-06-14 Thread sjames at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Sam James  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #16 from Sam James  ---
.

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2023-08-08 Thread arthur.j.odwyer at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Arthur O'Dwyer  changed:

   What|Removed |Added

 CC||arthur.j.odwyer at gmail dot 
com

--- Comment #15 from Arthur O'Dwyer  ---
The test case in #c10 seems to be fixed since GCC 12; the rest were fixed since
GCC 11. Should this bug be RESOLVED FIXED at this point?
https://godbolt.org/z/d16x181xh

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-17 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Andrew Pinski  changed:

   What|Removed |Added

 CC||asolokha at gmx dot com

--- Comment #14 from Andrew Pinski  ---
*** Bug 101943 has been marked as a duplicate of this bug. ***

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-12 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

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

https://gcc.gnu.org/g:9b7ab853bf33106fd0539e36d6ce7730269026e1

commit r12-2873-g9b7ab853bf33106fd0539e36d6ce7730269026e1
Author: Jakub Jelinek 
Date:   Thu Aug 12 09:16:13 2021 +0200

c++: Fix ICE on defaulted spaceship with pointer return type [PR94162]

The spaceship-synth-neg6.C testcase ICEs because we call cat_tag_for
on the explicit return type, but pointer types don't have
TYPE_LINKAGE_IDENTIFIER.  The patch fixes that by checking for
CLASS_TYPE_P only and also adds verification that it is in std
namespace, so we don't return non-cc_last for
my_namespace::partial_ordering.

The g++.dg/cpp2a/spaceship-synth11.C testcase is from a PR that has been
fixed with r12-619-gfc178519771db508c03611cff4a1466cf67fce1d (but
not backported to 11).

2021-08-12  Jakub Jelinek  

gcc/cp/
PR c++/94162
* method.c (cat_tag_for): Return cc_last for !CLASS_TYPE_P
or for classes not in std namespace.
gcc/testsuite/
PR c++/99429
* g++.dg/cpp2a/spaceship-synth11.C: New test.

PR c++/94162
* g++.dg/cpp2a/spaceship-synth-neg6.C: New test.

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-09 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

--- Comment #12 from Jakub Jelinek  ---
At least the #c8 testcase got fixed with
r12-619-gfc178519771db508c03611cff4a1466cf67fce1d
but that hasn't been backported to 11.x.

The ICE with int * return type is because POINTER_TYPE has NULL
TYPE_LINKAGE_IDENTIFIER, and cat_type_for is called on such type.
--- gcc/cp/method.c.jj  2021-06-28 22:38:27.014617793 +0200
+++ gcc/cp/method.c 2021-08-09 10:59:02.324443669 +0200
@@ -1029,6 +1029,8 @@ is_cat (tree type, comp_cat_tag tag)
 static comp_cat_tag
 cat_tag_for (tree type)
 {
+  if (!TYPE_LINKAGE_IDENTIFIER (type))
+return cc_last;
   for (int i = 0; i < cc_last; ++i)
 {
   comp_cat_tag tag = (comp_cat_tag)i;
would fix this (or shall we instead test if (!CLASS_TYPE_P (type)) or something
similar?

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-08 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Andrew Pinski  changed:

   What|Removed |Added

  Known to work|11.1.0  |

--- Comment #11 from Andrew Pinski  ---
(In reply to Cameron from comment #10)
> Notice the use of 'int*' as the comparison type.  GCC11 series will still
> crash.

Confirmed, this testcase ICEs on the trunk also.

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-08 Thread dacamara.cameron at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

--- Comment #10 from Cameron  ---
(In reply to Andrew Pinski from comment #9)
> None of the testcases ICE in GCC 11+

I notice that if I change the repro to:

#include 

struct S {
  int a;
  int* operator<=>(const S&) const = default;
};

bool b = S{} < S{};


Notice the use of 'int*' as the comparison type.  GCC11 series will still
crash.

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-08-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Andrew Pinski  changed:

   What|Removed |Added

  Known to work||11.1.0
  Known to fail||10.1.0

--- Comment #9 from Andrew Pinski  ---
None of the testcases ICE in GCC 11+

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-03-08 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

--- Comment #8 from Jakub Jelinek  ---
Test from PR99429:
namespace std {
struct strong_ordering {
  int _v;
  constexpr strong_ordering (int v) :_v(v) {}
  constexpr operator int (void) const { return _v; }
  static const strong_ordering less;
  static const strong_ordering equal;
  static const strong_ordering greater;
};
constexpr strong_ordering strong_ordering::less = -1;
constexpr strong_ordering strong_ordering::equal = 0;
constexpr strong_ordering strong_ordering::greater = 1;
}

template 
struct duration {
  static constexpr const long period = N;
  constexpr duration (void) = default;
  constexpr duration (const duration& d) = default;
  constexpr bool operator== (const duration& d) const = default;
  constexpr bool operator<=> (const duration& d) const = default;
  long _d;
};

using nanoseconds = duration<1>;
using microseconds = duration;

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2021-03-08 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Jakub Jelinek  changed:

   What|Removed |Added

 CC||msharov at users dot 
sourceforge.n
   ||et

--- Comment #7 from Jakub Jelinek  ---
*** Bug 99429 has been marked as a duplicate of this bug. ***

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-08-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Marek Polacek  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2020-08-18

--- Comment #6 from Marek Polacek  ---
Test from Bug 96627:

#include 

struct Float {
float value;

constexpr Float(float value) : value (value) {}

constexpr bool operator == (Float other) const noexcept {
return abs(value - other.value) < 0.5;
}

constexpr bool operator != (Float other) const noexcept {
return !(*this == other);
}

constexpr bool operator <=> (const Float& other) const noexcept = default;
};

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-08-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #5 from Marek Polacek  ---
Test from bug 96060:

#include 

struct xx {
int a;
int operator<=>(const xx&) const = default;
};

int f(std::set ) {
x.emplace(0);
return 0;
}

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-08-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Marek Polacek  changed:

   What|Removed |Added

 CC||nunoplopes at sapo dot pt

--- Comment #4 from Marek Polacek  ---
*** Bug 96060 has been marked as a duplicate of this bug. ***

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-08-18 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

Marek Polacek  changed:

   What|Removed |Added

 CC||poul250 at yandex dot ru

--- Comment #3 from Marek Polacek  ---
*** Bug 96627 has been marked as a duplicate of this bug. ***

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-03-14 Thread dacamara.cameron at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

--- Comment #2 from Cameron  ---
(In reply to Jakub Jelinek from comment #1)
> It isn't clear to me what exactly disallows it, perhaps
> http://eel.is/c++draft/class.spaceship#2.2
> ?
> For auto return type
> http://eel.is/c++draft/class.spaceship#4
> defines what return type it should have.
> If the explicit return type isn't auto, but is one of the
> std::{strong,weak,partial}_ordering, we don't ICE and accept it, should we
> and what behavior should it have?
> #include 
> struct S {
>   float a;
>   std::strong_ordering operator<=>(const S&) const = default;
> };
> bool b = S{} < S{};
> struct T {
>   std::partial_ordering operator<=>(const T&) const = default;
> };
> bool c = T{} < T{};
> For S, the auto return type would be std::partial_ordering and in the
> generated body we just assume the floats will not be unordered.
> So, for bool, shall it be accepted and handled some way, or shall it be
> deleted, or result in immediate error (ill-formed)?
> What about even weirder types (say float or int * or some arbitrary class)?

As you point out, the standard isn't clear about what to do in the case where
the comparison function does not return 'auto' or any of the comparison type
forms.

Our compiler (MSVC) now opts to issue a diag at the point of definition when a
nonsense return type is specified.  There is, unfortunately, room for
implementation divergence here.

Not ICEing--as we once did--is a good start though :).

[Bug c++/94162] ICE [neg] bad return type in defaulted <=>

2020-03-13 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94162

--- Comment #1 from Jakub Jelinek  ---
It isn't clear to me what exactly disallows it, perhaps
http://eel.is/c++draft/class.spaceship#2.2
?
For auto return type
http://eel.is/c++draft/class.spaceship#4
defines what return type it should have.
If the explicit return type isn't auto, but is one of the
std::{strong,weak,partial}_ordering, we don't ICE and accept it, should we and
what behavior should it have?
#include 
struct S {
  float a;
  std::strong_ordering operator<=>(const S&) const = default;
};
bool b = S{} < S{};
struct T {
  std::partial_ordering operator<=>(const T&) const = default;
};
bool c = T{} < T{};
For S, the auto return type would be std::partial_ordering and in the generated
body we just assume the floats will not be unordered.
So, for bool, shall it be accepted and handled some way, or shall it be
deleted, or result in immediate error (ill-formed)?
What about even weirder types (say float or int * or some arbitrary class)?