int main() {
auto f = [](unsigned x) { return x == sizeof(int); };
return []<class T>(T) requires (f(sizeof(T))) { return 99; }(12);
}
Clang13.0.0 5f6b3d1 and MSVC19.29.29917 accept; gcc11.0.1 20210407 rejects complaining that f is not captured:
In substitution of 'template<class T> main()::<lambda(T)> [with T = int]':
3:65: required from here
3:12: required by the constraints of 'template<class T> main()::<lambda(T)>'
3:38: error: 'f' is not captured
3 | return []<class T>(T) requires (f(sizeof(T))) { return 99; }(12);
| ~~^~~~~~~~~~~~
However, if f is captured explicitly (either by value or by reference) gcc still complains that it is not captured ♀️:
error: 'f' is not captured
3 | return [f]<class T>(T) requires (f(sizeof(T))) { return 99; }(12);
| ~~^~~~~~~~~~~~
~^~ what's this then?
And if a capture-default is provided (either & or =) gcc ices:
3:39: internal compiler error: trying to capture 'f' in instantiation of generic lambda
3 | return [&]<class T>(T) requires (f(sizeof(T))) { return 99; }(12);
| ~~^~~~~~~~~~~~
0x1cfdb99 internal_error(char const*, ...)
0x7ffd56 add_capture(tree_node*, tree_node*, tree_node*, bool, bool)
0x8000ea add_default_capture(tree_node*, tree_node*, tree_node*)
0x73f30a constraints_satisfied_p(tree_node*, tree_node*)
0x954dc3 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool, bool)
0x6e258e build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
0x980f05 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool, bool, int)
0x8e173d c_parse_file()
0xa60682 c_common_parse_file()
Is this a bug in gcc (well, apart from the ice), or are MSVC and clang wrong to accept?