7e0f147a29
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.
29 lines
888 B
C
29 lines
888 B
C
// { dg-do assemble }
|
|
// GROUPS passed access
|
|
// (Message bugs/access:3)
|
|
// From: jamshid@ses.com (Jamshid Afshar)
|
|
// Date: Wed, 2 Mar 94 18:24:22 CST
|
|
// Subject: g++ 2.5.5 doesn't warn about inaccessible virtual base ctor
|
|
// Message-ID: <9403030024.AA04534@ses.com>
|
|
|
|
class ForceLeafSterile {
|
|
friend class Sterile;
|
|
ForceLeafSterile() {} // { dg-message "" }
|
|
};
|
|
|
|
class Sterile : private virtual ForceLeafSterile // { dg-message "" }
|
|
{
|
|
public:
|
|
Sterile() {}
|
|
Sterile(const char* /*blah*/) {}
|
|
};
|
|
|
|
class Illegitimate : public Sterile {
|
|
public:
|
|
Illegitimate() {} // { dg-error "" } can't access virtual base deflt ctor
|
|
Illegitimate(const char* /*blah*/)
|
|
: ForceLeafSterile() {} // { dg-error "" } can't access default ctor
|
|
Illegitimate(const Illegitimate&)
|
|
{} // { dg-error "" } can't access default ctor
|
|
};
|