c++: using lookup within class defn [PR104476]
authorJason Merrill <jason@redhat.com>
Fri, 25 Feb 2022 19:07:15 +0000 (15:07 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 18 Mar 2022 18:07:58 +0000 (14:07 -0400)
commit47da5198766256be658b4c321cecfd6039b0b91b
treecf04525e4d62c0579f27fdaba87433023f92400d
parent32ca611c42658948f1b8883994796f35e8b4e74d
c++: using lookup within class defn [PR104476]

The problem in both PR92918 and PR104476 is overloading of base member
functions brought in by 'using' with direct member functions during parsing
of the class body.  To this point they've had a troublesome coexistence
which was resolved by set_class_bindings when the class is complete, but we
also need to handle lookup within the class body, such as in a trailing
return type.

The problem was that push_class_level_binding would either clobber the
using-decl with the direct members or vice-versa.  In older versions of GCC
we only pushed dependent usings, and preferring the dependent using made
sense, as it expresses a type-dependent overload set that we can't do
anything useful with.  But when we started keeping non-dependent usings
around, push_class_level_binding in particular wasn't adjusted accordingly.

This patch makes that adjustment, and pushes the functions imported by a
non-dependent using immediately from finish_member_declaration.  This made
diagnosing redundant using-decls a bit awkward, since we no longer push the
using-decl itself; I handle that by noticing when we try to add the same
function again and searching TYPE_FIELDS for the previous using-decl.

PR c++/92918
PR c++/104476

gcc/cp/ChangeLog:

* class.cc (add_method): Avoid adding the same used function twice.
(handle_using_decl): Don't add_method.
(finish_struct): Don't using op= if we have one already.
(maybe_push_used_methods): New.
* semantics.cc (finish_member_declaration): Call it.
* name-lookup.cc (diagnose_name_conflict): No longer static.
(push_class_level_binding): Revert 92918 patch, limit
to dependent using.
* cp-tree.h: Adjust.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/pr85070.C: Remove expected error.
* g++.dg/lookup/using66a.C: New test.
* g++.dg/lookup/using67.C: New test.
gcc/cp/class.cc
gcc/cp/cp-tree.h
gcc/cp/name-lookup.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/cpp0x/pr85070.C
gcc/testsuite/g++.dg/lookup/using66a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/lookup/using67.C [new file with mode: 0644]