https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51577
Patrick Palka <ppalka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ppalka at gcc dot gnu.org --- Comment #18 from Patrick Palka <ppalka at gcc dot gnu.org> --- If the dependent operator call is inside a lambda, e.g. when adjusting the testcase in comment #1 to: template<typename T> void test( T v ) { [&] { +v; } } namespace A { struct X { }; } void operator+(A::X) { } int main() { test( A::X() ); } then GCC 11 correctly rejects the testcase: 51577.C: In instantiation of ‘bool test(T, U) [with T = A::X; U = B::Y]’: 51577.C:23:7: required from here 51577.C:5:14: error: no match for ‘operator==’ (operand types are ‘A::X’ and ‘B::Y’) 5 | [&] { v1 == v2; }; | ~~~^~~~~ ever since Nathan's r11-2876. As this commit mentions, should we enable the maybe_save_operator_binding / push_operator_binding mechanism for all templates? Something like --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -9116,7 +9116,7 @@ static const char *const op_bind_attrname = "operator bindings"; void maybe_save_operator_binding (tree e) { - /* This is only useful in a generic lambda. */ + /* This is only useful in a template. */ if (!processing_template_decl) return; @@ -9124,11 +9124,6 @@ maybe_save_operator_binding (tree e) if (!cfn) return; - /* Do this for lambdas and code that will emit a CMI. In a module's - GMF we don't yet know whether there will be a CMI. */ - if (!module_has_cmi_p () && !global_purview_p () && !current_lambda_expr()) - return; - tree fnname = ovl_op_identifier (false, TREE_CODE (e)); if (!fnname) return; seems to fix all the related testcases I tried.