+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.
/* 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;
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.
--- /dev/null
+// { 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)();
+ }
+};
--- /dev/null
+// { 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" }
+ }
+};