]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: memfn lookup consistency in incomplete-class ctx
authorPatrick Palka <ppalka@redhat.com>
Mon, 20 Dec 2021 20:02:40 +0000 (15:02 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 20 Dec 2021 20:02:40 +0000 (15:02 -0500)
commitab85331c58223e483c55ff0316a92265d7910e9b
tree65cc274dfb8bb38d9b45e6e99b5f9eb903ef6f6c
parentb3f58f87d78b958e35e4a44f5fdb4b7721cb2837
c++: memfn lookup consistency in incomplete-class ctx

When instantiating a call to a member function of a class template, we
repeat the member function lookup in order to obtain the corresponding
partially instantiated functions.  Within an incomplete-class context
however, we need to be more careful when repeating the lookup because we
don't want to introduce later-declared member functions that weren't
visible at template definition time.  We're currently not careful enough
in this respect, which causes us to reject memfn1.C below.

This patch fixes this issue by making tsubst_baselink filter out from
the instantiation-time lookup those member functions that were invisible
at template definition time.  This is really only necessary within an
incomplete-class context, so this patch adds a heuristic flag to BASELINK
to help us avoid needlessly performing this filtering step (which would
be a no-op) in complete-class contexts.

This is also necessary for the ahead-of-time overload set pruning
implemented in r12-6075 to be effective for member functions within
class templates.

gcc/cp/ChangeLog:

* call.c (build_new_method_call): Set
BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P on the pruned baselink.
* cp-tree.h (BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P): Define.
* pt.c (filter_memfn_lookup): New subroutine of tsubst_baselink.
(tsubst_baselink): Use filter_memfn_lookup on the new lookup
result when BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P is set on the
old baselink.  Remove redundant BASELINK_P check.
* search.c (build_baselink): Set
BASELINK_FUNCTIONS_MAYBE_INCOMPLETE_P appropriately.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/memfn1.C: New test.
* g++.dg/template/non-dependent16b.C: New test.
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/pt.c
gcc/cp/search.c
gcc/testsuite/g++.dg/lookup/memfn1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/non-dependent16b.C [new file with mode: 0644]