Commit 38afd588 by Mark Mitchell Committed by Mark Mitchell

cp-tree.h (enforce_access): Declare.

Wed Mar 25 16:10:50 1998  Mark Mitchell  <mmitchell@usa.net>
	* cp-tree.h (enforce_access): Declare.
	* call.c (enforce_access): Make it extern, not static.
	* class.c (alter_access): Use enforce_access; modify code for ISO
	compliance, rather than ARM rules.

From-SVN: r18832
parent 4d4c4d45
Wed Mar 25 16:10:50 1998 Mark Mitchell <mmitchell@usa.net>
* cp-tree.h (enforce_access): Declare.
* call.c (enforce_access): Make it extern, not static.
* class.c (alter_access): Use enforce_access; modify code for ISO
compliance, rather than ARM rules.
Wed Mar 25 12:10:45 1998 Kriang Lerdsuwanakij <lerdsuwa@scf.usc.edu> Wed Mar 25 12:10:45 1998 Kriang Lerdsuwanakij <lerdsuwa@scf.usc.edu>
* cp-tree.h: Fix typo. * cp-tree.h: Fix typo.
......
...@@ -51,7 +51,6 @@ static int compare_qual PROTO((tree, tree)); ...@@ -51,7 +51,6 @@ static int compare_qual PROTO((tree, tree));
static int compare_ics PROTO((tree, tree)); static int compare_ics PROTO((tree, tree));
static tree build_over_call PROTO((tree, tree, tree, int)); static tree build_over_call PROTO((tree, tree, tree, int));
static tree convert_default_arg PROTO((tree, tree)); static tree convert_default_arg PROTO((tree, tree));
static void enforce_access PROTO((tree, tree));
static tree convert_like PROTO((tree, tree)); static tree convert_like PROTO((tree, tree));
static void op_error PROTO((enum tree_code, enum tree_code, tree, tree, static void op_error PROTO((enum tree_code, enum tree_code, tree, tree,
tree, char *)); tree, char *));
...@@ -2949,26 +2948,26 @@ build_op_delete_call (code, addr, size, flags) ...@@ -2949,26 +2948,26 @@ build_op_delete_call (code, addr, size, flags)
return error_mark_node; return error_mark_node;
} }
/* If the current scope isn't allowed to access FUNCTION along /* If the current scope isn't allowed to access DECL along
BASETYPE_PATH, give an error. */ BASETYPE_PATH, give an error. */
static void void
enforce_access (basetype_path, function) enforce_access (basetype_path, decl)
tree basetype_path, function; tree basetype_path, decl;
{ {
tree access = compute_access (basetype_path, function); tree access = compute_access (basetype_path, decl);
if (access == access_private_node) if (access == access_private_node)
{ {
cp_error_at ("`%+#D' is %s", function, cp_error_at ("`%+#D' is %s", decl,
TREE_PRIVATE (function) ? "private" TREE_PRIVATE (decl) ? "private"
: "from private base class"); : "from private base class");
error ("within this context"); error ("within this context");
} }
else if (access == access_protected_node) else if (access == access_protected_node)
{ {
cp_error_at ("`%+#D' %s", function, cp_error_at ("`%+#D' %s", decl,
TREE_PROTECTED (function) ? "is protected" TREE_PROTECTED (decl) ? "is protected"
: "has protected accessibility"); : "has protected accessibility");
error ("within this context"); error ("within this context");
} }
......
...@@ -1310,34 +1310,25 @@ alter_access (t, fdecl, access) ...@@ -1310,34 +1310,25 @@ alter_access (t, fdecl, access)
tree access; tree access;
{ {
tree elem = purpose_member (t, DECL_ACCESS (fdecl)); tree elem = purpose_member (t, DECL_ACCESS (fdecl));
if (elem && TREE_VALUE (elem) != access) if (elem)
{ {
if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL) if (TREE_VALUE (elem) != access)
{ {
cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl)); if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
else
error ("conflicting access specifications for field `%s', ignored",
IDENTIFIER_POINTER (DECL_NAME (fdecl)));
} }
else else
error ("conflicting access specifications for field `%s', ignored", /* They're changing the access to the same thing they changed
IDENTIFIER_POINTER (DECL_NAME (fdecl))); it to before. That's OK. */
} ;
else if (TREE_PRIVATE (fdecl))
{
if (access != access_private_node)
cp_error_at ("cannot make private `%D' non-private", fdecl);
goto alter;
} }
else if (TREE_PROTECTED (fdecl)) else
{
if (access != access_protected_node)
cp_error_at ("cannot make protected `%D' non-protected", fdecl);
goto alter;
}
/* ARM 11.3: an access declaration may not be used to restrict access
to a member that is accessible in the base class. */
else if (access != access_public_node)
cp_error_at ("cannot reduce access of public member `%D'", fdecl);
else if (elem == NULL_TREE)
{ {
enforce_access (TYPE_BINFO (t), fdecl);
alter: alter:
DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl)); DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
return 1; return 1;
......
...@@ -2085,6 +2085,7 @@ extern tree build_op_new_call PROTO((enum tree_code, tree, tree, int)); ...@@ -2085,6 +2085,7 @@ extern tree build_op_new_call PROTO((enum tree_code, tree, tree, int));
extern tree build_op_delete_call PROTO((enum tree_code, tree, tree, int)); extern tree build_op_delete_call PROTO((enum tree_code, tree, tree, int));
extern int can_convert PROTO((tree, tree)); extern int can_convert PROTO((tree, tree));
extern int can_convert_arg PROTO((tree, tree, tree)); extern int can_convert_arg PROTO((tree, tree, tree));
extern void enforce_access PROTO((tree, tree));
/* in class.c */ /* in class.c */
extern tree build_vbase_path PROTO((enum tree_code, tree, tree, tree, int)); extern tree build_vbase_path PROTO((enum tree_code, tree, tree, tree, int));
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// GROUPS passed old-abort // GROUPS passed old-abort
struct B struct B
{ {
void f(char); // ERROR - Cannot reduce access void f(char);
void g(char); void g(char);
}; };
......
class D2;
class B {
private:
int a;
protected:
int b;
friend class D2;
};
class D : public B {
public:
using B::a;
using B::b;
};
class D2 : public B {
public:
using B::a;
using B::b;
private:
using B::b;
}; // ERROR - conflicting access specifications
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