PR c++/88123 - lambda and using-directive.
authorJason Merrill <jason@redhat.com>
Fri, 8 Mar 2019 02:54:41 +0000 (21:54 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 8 Mar 2019 02:54:41 +0000 (21:54 -0500)
commitbddee796d0b4800b5ac3d7e7e9e315c23799424d
tree0c9cd89344be1024c157c899c00e236942538921
parent1ce59b6cad83d5ca6f1efee83f910d8b677a976a
PR c++/88123 - lambda and using-directive.

For named function calls in a template, the result of unqualified lookup is
safed in CALL_EXPR_FN.  But for operator expressions, no unqualified lookup
is performed until we know whether the operands have class type.  So when we
see in a lambda a use of an operator that might be overloaded, we need to do
that lookup then and save it away somewhere.  One possibility would be in
the expression, but we can't really add extra conditional operands to
standard tree codes.  I mostly implemented another approach using a new
WITH_LOOKUP_EXPR code, but teaching everywhere how to handle a new tree code
is always complicated.  Then it occurred to me that we could associate the
lookups with the function, which is both simpler and smaller.  So this patch
stores any operator bindings needed by a lambda function in an internal
attribute on the lambda call operator.

* name-lookup.c (op_unqualified_lookup)
(maybe_save_operator_binding, discard_operator_bindings)
(push_operator_bindings): New.
* typeck.c (build_x_binary_op, build_x_unary_op): Call
maybe_save_operator_binding.
* decl.c (start_preparsed_function): Call push_operator_bindings.
* tree.c (cp_free_lang_data): Call discard_operator_bindings.

From-SVN: r269477
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/cp/name-lookup.h
gcc/cp/tree.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/cpp1y/lambda-generic-using1.C [new file with mode: 0644]