This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ PATCH: Fix PR142



Nested classes in anonymous unions are forbidden by the standard.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-07-19  Mark Mitchell  <mark@codesourcery.com>

	* class.c (finish_struct_anon): Forbid nested classes.

Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.393
diff -c -p -r1.393 class.c
*** class.c	2001/07/19 04:27:15	1.393
--- class.c	2001/07/19 07:19:24
*************** finish_struct_anon (t)
*** 3132,3138 ****
  	  tree elt = TYPE_FIELDS (TREE_TYPE (field));
  	  for (; elt; elt = TREE_CHAIN (elt))
  	    {
! 	      if (DECL_ARTIFICIAL (elt))
  		continue;
  
  	      if (DECL_NAME (elt) == constructor_name (t))
--- 3132,3145 ----
  	  tree elt = TYPE_FIELDS (TREE_TYPE (field));
  	  for (; elt; elt = TREE_CHAIN (elt))
  	    {
! 	      /* We're generally only interested in entities the user
! 		 declared, but we also find nested classes by noticing
! 		 the TYPE_DECL that we create implicitly.  You're
! 		 allowed to put one anonymous union inside another,
! 		 though, so we explicitly tolerate that.  */
! 	      if (DECL_ARTIFICIAL (elt) 
! 		  && (!DECL_IMPLICIT_TYPEDEF_P (elt)
! 		      || ANON_AGGR_TYPE_P (TREE_TYPE (elt))))
  		continue;
  
  	      if (DECL_NAME (elt) == constructor_name (t))
Index: testsuite/g++.old-deja/g++.jason/anon3.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.jason/anon3.C,v
retrieving revision 1.2
diff -c -p -r1.2 anon3.C
*** anon3.C	1998/12/16 21:31:53	1.2
--- anon3.C	2001/07/19 07:19:27
*************** public:
*** 8,14 ****
  private:
    union {
      float vf;
!     struct ff {
        void *ptr;
        char *name;
        int sz;
--- 8,14 ----
  private:
    union {
      float vf;
!     struct ff { // ERROR - nested class in anonymous union
        void *ptr;
        char *name;
        int sz;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]