https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113427
Bug ID: 113427
Summary: ICE: tree check: C++23 `this auto` lambda + multiple
(ambiguous) inheritance from closure type
Product: gcc
Version: unknown
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/fd3zzfrTd
auto factory(int x) {
return [x=x](this auto self) { return x; };
}
using Lambda = decltype(factory(0));
struct LeftCat : Lambda { LeftCat() : Lambda(factory(1)) {} };
struct RightCat : Lambda { RightCat() : Lambda(factory(2)) {} };
struct SiameseCat : LeftCat, RightCat { using Lambda::operator(); };
int main() {
return SiameseCat()();
}
===
<source>: In instantiation of 'factory(int)::<lambda(this auto:1)> [with auto:1
= SiameseCat]':
<source>:11:24: required from here
11 | return SiameseCat()();
| ~~~~~~~~~~~~^~
<source>:3:32: error: 'factory(int)::<lambda(this auto:1)>' is an ambiguous
base of 'SiameseCat'
3 | return [x=x](this auto self) { return x; };
| ^
<source>:3:32: error: 'factory(int)::<lambda(this auto:1)>' is an ambiguous
base of 'SiameseCat'
<source>:3:32: internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in tsubst_decl, at cp/pt.cc:15542
0x264113c internal_error(char const*, ...)
???:0
0x9641cf tree_class_check_failed(tree_node const*, tree_code_class, char
const*, int, char const*)
???:0
0xa88c8c tree_class_check(tree_node*, tree_code_class, char const*, int, char
const*)
???:0
0xc88d63 instantiate_decl(tree_node*, bool, bool)
???:0
0xb4de55 maybe_instantiate_decl(tree_node*)
???:0
0xb4f948 mark_used(tree_node*, int)
???:0
0xa81a04 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
???:0
0xcce9e7 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0xc521ea c_parse_file()
???:0
0xda5b99 c_common_parse_file()
???:0
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.
===
Found by noodling around with explicit object parameters and corner cases
related to https://eel.is/c++draft/expr.prim.lambda#closure-5 . That wording
currently demands that the explicit object parameter of a capturing lambda be
"a class type derived from the closure type," but it probably ought to say more
like "a class type _unambiguously_ derived from the closure type." At least, I
don't know what the expected behavior of the above program ought to be, if it's
_not_ supposed to be ill-formed. I think GCC's ICE happens because GCC is
trying too hard to assign a meaning to an essentially meaningless program.