c++: dependent operator expression lookup [PR51577]
authorPatrick Palka <ppalka@redhat.com>
Tue, 11 May 2021 02:38:34 +0000 (22:38 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 11 May 2021 02:38:34 +0000 (22:38 -0400)
commit6ab1176667734bd6de20833f8d263c03a418c452
tree54a7d24547cd60bdd00ee67ea186c89dbfa4746b
parente7a9f085ffd34b0d7bc4b803c182b41494f609aa
c++: dependent operator expression lookup [PR51577]

This unconditionally enables the maybe_save_operator_binding mechanism
for all function templates, so that when resolving a dependent operator
expression from a function template we ignore later-declared
namespace-scope bindings that weren't visible at template definition
time.  This patch additionally makes the mechanism apply to dependent
comma and compound-assignment operator expressions.

Note that this doesn't fix the testcases in PR83035 or PR99692 because
there the dependent operator expressions aren't at function scope.  I'm
not sure how adapt this mechanism for these testcases, since although
we'll in both testcases have a TEMPLATE_DECL to associate the lookup
result with, at instantiation time we won't have an appropriate binding
level to push to.

gcc/cp/ChangeLog:

PR c++/51577
* name-lookup.c (maybe_save_operator_binding): Unconditionally
enable for all function templates, not just generic lambdas.
Handle compound-assignment operator expressions.
* typeck.c (build_x_compound_expr): Call maybe_save_operator_binding
in the type-dependent case.
(build_x_modify_expr): Likewise.  Move declaration of 'op' closer
to its first use.

gcc/testsuite/ChangeLog:

PR c++/51577
* g++.dg/lookup/operator-3.C: New test.
gcc/cp/name-lookup.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/lookup/operator-3.C [new file with mode: 0644]