g++-10 internal compiler error In member function ‘constexpr std::strong_ordering S9::operator<=>(const S9&) const’
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-10 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Command Line:
g++-10 -std=c++20 -c strong_
stderr:
strong_
strong_
69 | std::strong_
| ^~~~~~~~
0x7fdb22256082 __libc_start_main
../csu/
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <file:/
code:
#include<compare>
// not in our immediate control
struct Legacy
{
bool operator==(Legacy const&) const;
bool operator<(Legacy const&) const;
};
struct S6
{
int x;
Legacy l;
// deleted because Legacy doesn't have operator<=>(), comparison category
// can't be deduced
auto operator<=>(const S6&) const = default;
};
struct S7
{
int x;
Legacy l;
std:
/*
Since comparison category is provided explicitly, ordering can be
synthesized using operator<() and operator==(). They must return exactly
`bool` for this to work. It will work for weak and partial ordering as well.
Here's an example of synthesized operator<=>():
std:
{
// use operator<=>() for int
if(auto cmp = x <=> rhs.x; cmp != 0) return cmp;
// synthesize ordering for Legacy using operator<() and operator==()
if(l == rhs.l) return std::strong_
if(l < rhs.l) return std::strong_
return std::strong_
}
*/
};
struct NoEqual
{
bool operator<(const NoEqual&) const = default;
};
struct S8
{
NoEqual n;
// deleted, NoEqual doesn't have operator<=>()
// auto operator<=>(const S8&) const = default;
// deleted as well because NoEqual doesn't have operator==()
std:
};
struct W
{
std:
};
struct S9
{
W w;
// ask for strong_ordering but W can provide only weak_ordering, this will
// yield an error during instantiation
std:
void f()
{
(S9{} <=> S9{}); // error
}
};
this is fixed in GCC 11 and up:
tst.cc: In member function ‘void S9::f()’: ordering S9::operator< =>(const S9&) const’ ordering S9::operator< =>(const S9&) const’ is implicitly deleted because the default definition would be ill-formed: ordering operator<=>(const S9&) const = default; ordering’ , which does not convert to ‘std::strong_ ordering’
tst.cc:72:22: error: use of deleted function ‘constexpr std::strong_
72 | (S9{} <=> S9{}); // error
| ^
tst.cc:69:26: note: ‘constexpr std::strong_
69 | std::strong_
| ^~~~~~~~
tst.cc:66:7: error: three-way comparison of ‘S9::w’ has type ‘std::weak_
66 | W w;
| ^