* class.c (finish_struct_anon): Forbid nested classes.
authorMark Mitchell <mark@codesourcery.com>
Thu, 19 Jul 2001 07:22:40 +0000 (07:22 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Thu, 19 Jul 2001 07:22:40 +0000 (07:22 +0000)
From-SVN: r44148

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/g++.old-deja/g++.jason/anon3.C

index 0fa3fdb4bc8943315ac51ebaf07d15fdea7f182a..fb7d6c1ec769b17a245b0ad8e62ef38d01ce7476 100644 (file)
@@ -1,3 +1,7 @@
+2001-07-19  Mark Mitchell  <mark@codesourcery.com>
+
+       * class.c (finish_struct_anon): Forbid nested classes.
+
 2001-07-19  Neil Booth  <neil@daikokuya.demon.co.uk>
 
        * decl2.c: Don't include dwarfout.h and dwarf2out.h.
index c3aa297236b513fc63e33a032807cba87cc9ff8d..087b7c807ef0fab8c71bd7a435a59989fa73f473 100644 (file)
@@ -3132,7 +3132,14 @@ finish_struct_anon (t)
          tree elt = TYPE_FIELDS (TREE_TYPE (field));
          for (; elt; elt = TREE_CHAIN (elt))
            {
-             if (DECL_ARTIFICIAL (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 b3f05f8ad14cd6b3811f01ab1f86be1487cddc43..96353fcc97b1600817aedf599ce564aa495ec616 100644 (file)
@@ -8,7 +8,7 @@ public:
 private:
   union {
     float vf;
-    struct ff {
+    struct ff { // ERROR - nested class in anonymous union
       void *ptr;
       char *name;
       int sz;