Commit b54f5338 by Kriang Lerdsuwanakij Committed by Kriang Lerdsuwanakij

re PR c++/11174 (derived class can access protected base class member function…

re PR c++/11174 (derived class can access protected base class member function through pointer to member function)

	PR c++/11174
	* init.c (build_offset_ref): Perform access checking for
	pointer to member correctly.

	* g++.dg/parse/access4.C: New test.
	* g++.dg/parse/access5.C: Likewise.
	* g++.old-deja/g++.jason/access17.C: Adjust error message.

From-SVN: r70566
parent 3ab37c7d
2003-08-19 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11174
* init.c (build_offset_ref): Perform access checking for
pointer to member correctly.
2003-08-19 Gabriel Dos Reis <gdr@integrable-solutions.net>
* cp-lang.c (LANG_HOOKS_INITIALIZE_DIAGNOSTICS): Fix spelling.
......
......@@ -1502,8 +1502,20 @@ build_offset_ref (tree type, tree name, bool address_p)
/* Get rid of a potential OVERLOAD around it */
t = OVL_CURRENT (t);
/* unique functions are handled easily. */
perform_or_defer_access_check (basebinfo, t);
/* Unique functions are handled easily. */
/* For non-static member of base class, we need a special rule
for access checking [class.protected]:
If the access is to form a pointer to member, the
nested-name-specifier shall name the derived class
(or any class derived from that class). */
if (address_p && DECL_P (t)
&& DECL_NONSTATIC_MEMBER_P (t))
perform_or_defer_access_check (TYPE_BINFO (type), t);
else
perform_or_defer_access_check (basebinfo, t);
mark_used (t);
if (DECL_STATIC_FUNCTION_P (t))
return t;
......@@ -1515,6 +1527,11 @@ build_offset_ref (tree type, tree name, bool address_p)
member = fnfields;
}
}
else if (address_p && TREE_CODE (member) == FIELD_DECL)
/* We need additional test besides the one in
check_accessibility_of_qualified_id in case it is
a pointer to non-static member. */
perform_or_defer_access_check (TYPE_BINFO (type), member);
if (!address_p)
{
......
2003-08-19 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/11174
* g++.dg/parse/access4.C: New test.
* g++.dg/parse/access5.C: Likewise.
* g++.old-deja/g++.jason/access17.C: Adjust error message.
2003-08-18 Matt Kraai <kraai@alumni.cmu.edu>
* gcc.dg/noncompile/20030818-1.c: New.
......
// { dg-do compile }
// Origin: Mike Reed <mike.reed@amadron.com>
// PR c++/11174: Access checking of pointer-to-member function
class A {
protected:
void foo() {} // { dg-error "protected" }
public:
A();
};
class B : public A {
void bar() {
A a;
void (A::*pmf)() = &A::foo; // { dg-error "this context" }
(a.*pmf)();
}
};
// { dg-do compile }
// Origin: Giovanni Bajo <giovannibajo@libero.it>
// PR c++/11174: Access checking on pointer to member data.
struct A
{
protected:
int a; // { dg-error "protected" }
};
struct B : A
{
void foo() {
(void)&A::a; // { dg-error "this context" }
}
};
......@@ -13,7 +13,7 @@ struct B: public A {
};
int A::* B::p = &A::i; // { dg-error "" }
int (A::* B::fp)() = &A::f; // ERROR -
int (A::* B::fp)() = &A::f; // { dg-error "" }
struct C {
static int A::*p;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment