c++: private inheritance access diagnostics fix [PR17314]
This patch fixes PR17314. Previously, when class C attempted
to access member a declared in class A through class B, where class B
privately inherits from A and class C inherits from B, GCC would correctly
report an access violation, but would erroneously report that the reason was
because a was "protected", when in fact, from the point of view of class C,
it was really "private". This patch updates the diagnostics code to generate
more correct errors in cases of failed inheritance such as these.
The reason this bug happened was because GCC was examining the
declared access of decl, instead of looking at it in the
context of class inheritance.
gcc/cp/ChangeLog:
2021-01-21 Anthony Sharp <anthonysharp15@gmail.com>
* call.c (complain_about_access): Altered function.
* cp-tree.h (complain_about_access): Changed parameters of function.
(get_parent_with_private_access): Declared new function.
* search.c (get_parent_with_private_access): Defined new function.
* semantics.c (enforce_access): Modified function.
* typeck.c (complain_about_unrecognized_member): Updated function
arguments in complain_about_access.
gcc/testsuite/ChangeLog:
2021-01-21 Anthony Sharp <anthonysharp15@gmail.com>
* g++.dg/lookup/scoped1.C: Modified testcase to run successfully
with changes.
* g++.dg/tc1/dr142.C: Same as above.
* g++.dg/tc1/dr52.C: Same as above.
* g++.old-deja/g++.brendan/visibility6.C: Same as above.
* g++.old-deja/g++.brendan/visibility8.C: Same as above.
* g++.old-deja/g++.jason/access8.C: Same as above.
* g++.old-deja/g++.law/access4.C: Same as above.
* g++.old-deja/g++.law/visibility12.C: Same as above.
* g++.old-deja/g++.law/visibility4.C: Same as above.
* g++.old-deja/g++.law/visibility8.C: Same as above.
* g++.old-deja/g++.other/access4.C: Same as above.
16 files changed: