PATCH for using declaration problem
Mark Mitchell
mmitchell@usa.net
Tue Mar 24 16:12:00 GMT 1998
Here's a patch to fix some mishandlings of using declarations reported
by Dallas Morlock.
--
Mark Mitchell <mmitchell@usa.net>
http://home.earthlink.net/~mbmitchell
Consulting Services Available
Tue Mar 24 12:26: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.
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.44
diff -c -p -r1.44 cp-tree.h
*** cp-tree.h 1998/03/24 10:25:36 1.44
--- cp-tree.h 1998/03/24 20:23:36
*************** extern tree build_op_new_call PROTO((e
*** 2085,2090 ****
--- 2085,2091 ----
extern tree build_op_delete_call PROTO((enum tree_code, tree, tree, int));
extern int can_convert PROTO((tree, tree));
extern int can_convert_arg PROTO((tree, tree, tree));
+ extern void enforce_access PROTO((tree, tree));
/* in class.c */
extern tree build_vbase_path PROTO((enum tree_code, tree, tree, tree, int));
Index: cp/class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.29
diff -c -p -r1.29 class.c
*** class.c 1998/03/24 10:25:37 1.29
--- class.c 1998/03/24 20:23:53
*************** alter_access (t, fdecl, access)
*** 1310,1343 ****
tree access;
{
tree elem = purpose_member (t, DECL_ACCESS (fdecl));
! if (elem && TREE_VALUE (elem) != access)
{
! 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 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))
! {
! 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)
! {
alter:
DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
return 1;
--- 1310,1334 ----
tree access;
{
tree elem = purpose_member (t, DECL_ACCESS (fdecl));
! if (elem)
{
! if (TREE_VALUE (elem) != access)
{
! 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
! /* They're changing the access to the same thing they changed
! it to before. That's OK. */
! ;
}
! else
{
! enforce_access (TYPE_BINFO (t), fdecl);
!
alter:
DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
return 1;
Index: cp/call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.52
diff -c -p -r1.52 call.c
*** call.c 1998/03/19 21:37:25 1.52
--- call.c 1998/03/24 20:24:03
*************** static int compare_qual PROTO((tree, tre
*** 51,57 ****
static int compare_ics PROTO((tree, tree));
static tree build_over_call PROTO((tree, tree, tree, int));
static tree convert_default_arg PROTO((tree, tree));
- static void enforce_access PROTO((tree, tree));
static tree convert_like PROTO((tree, tree));
static void op_error PROTO((enum tree_code, enum tree_code, tree, tree,
tree, char *));
--- 51,56 ----
*************** build_op_delete_call (code, addr, size,
*** 2952,2958 ****
/* If the current scope isn't allowed to access FUNCTION along
BASETYPE_PATH, give an error. */
! static void
enforce_access (basetype_path, function)
tree basetype_path, function;
{
--- 2951,2957 ----
/* If the current scope isn't allowed to access FUNCTION along
BASETYPE_PATH, give an error. */
! void
enforce_access (basetype_path, function)
tree basetype_path, function;
{
Index: testsuite/g++.old-deja/g++.other/using1.C
===================================================================
RCS file: using1.C
diff -N using1.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- using1.C Tue Mar 24 12:24:03 1998
***************
*** 0 ****
--- 1,26 ----
+ 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
+
More information about the Gcc-bugs
mailing list