c++: extraneous access error with ambiguous lookup [PR103177]
authorPatrick Palka <ppalka@redhat.com>
Tue, 15 Mar 2022 12:50:24 +0000 (08:50 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 15 Mar 2022 12:50:24 +0000 (08:50 -0400)
commitffe9c0a0d3564a6083ea6194eb3374a89c29c085
treeb2274a0a892c74c22dcc13065f892be7baaa105d
parent98afdc3e2bfccf0a1337013b54f2c5634ef40ee5
c++: extraneous access error with ambiguous lookup [PR103177]

When a lookup is ambiguous, lookup_member still attempts to check
access of the first member found before diagnosing the ambiguity and
propagating the error, and this may cause us to issue an extraneous
access error as in the testcase below (for B1::foo).

This patch fixes this by swapping the order of the ambiguity and access
checks within lookup_member.  In passing, since the only thing that could
go wrong during lookup_field_r is ambiguity, we might as well hardcode
that in lookup_member and get rid of lookup_field_info::errstr.

PR c++/103177

gcc/cp/ChangeLog:

* search.cc (lookup_field_info::errstr): Remove this data
member.
(lookup_field_r): Don't set errstr.
(lookup_member): Check ambiguity before checking access.
Simplify accordingly after errstr removal.  Exit early upon
error or empty result.

gcc/testsuite/ChangeLog:

* g++.dg/lookup/ambig6.C: New test.
gcc/cp/search.cc
gcc/testsuite/g++.dg/lookup/ambig6.C [new file with mode: 0644]