https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127456
Bug ID: 127456
Summary: ICE when defaulted operator<=> returns a reference
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: arthur.j.odwyer at gmail dot com
Target Milestone: ---
// https://godbolt.org/z/Y1GjqsvPE
#include <compare>
struct C {
int i;
const std::strong_ordering& operator<=>(const C&) const = default;
};
auto f(C c) { return c <=> c; }
This `operator<=>` should be defaulted-as-deleted. GCC 15 and 16 seem to get it
right, but the current trunk (the rising GCC 17) ICEs instead. At least it
would be good to add a regression test to the test suite.
<source>: In member function 'constexpr const std::strong_ordering&
C::operator<=>(const C&) const':
<source>:4:31: internal compiler error: in convert_like_internal, at
cp/call.cc:8738
4 | const std::strong_ordering& operator<=>(const C&) const = default;
| ^~~~~~~~
0x2c51b98 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x2c467db internal_error(char const*, ...)
???:0
0xb7d16a fancy_abort(char const*, int, char const*)
???:0
0xbb620e initialize_reference(tree_node*, tree_node*, int, int)
???:0
0xed8d50 convert_for_initialization(tree_node*, tree_node*, tree_node*, int,
impl_conv_rhs, tree_node*, int, int)
???:0
0xeda706 check_return_expr(tree_node*, bool*, bool*)
???:0
0xe73648 finish_return_stmt(tree_node*)
???:0
0xcf5f59 build_comparison_op(tree_node*, bool, int)
???:0
0xcf75fe synthesize_method(tree_node*)
???:0
0xca1e9a mark_used(tree_node*, int)
???:0
0xbb9b5a build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
???:0
0xebf4c2 build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
???:0
0xdd5df3 c_parse_file()
???:0
0xf69679 c_common_parse_file()
???:0
/cefs/19/194130150ca8d11081c00aaf_gcc-trunk-20260917/bin/../libexec/gcc/x86_64-linux-gnu/17.0.0/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/19/194130150ca8d11081c00aaf_gcc-trunk-20260917/bin/../lib/gcc/x86_64-linux-gnu/17.0.0/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -std=c++26
-fdiagnostics-color=always -fno-verbose-asm -o /app/output.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1