re PR c++/5659 (default access for class/struct bug)
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 12 Mar 2002 23:32:47 +0000 (23:32 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 12 Mar 2002 23:32:47 +0000 (23:32 +0000)
cp:
PR c++/5659
* decl.c (xref_tag): Don't set CLASSTYPE_DECLARED_CLASS here.
* decl2.c (handle_class_head): Set CLASSTYPE_DECLARED_CLASS for
definitions.
testsuite:
* g++.dg/other/access1.C: New test.

From-SVN: r50692

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/access1.C [new file with mode: 0644]

index 1ad21d39d113c7d0a87743f88c8503ce548899c5..e9d8283d014f8b7f68348ab8fe6e70b472ac2f8a 100644 (file)
@@ -1,3 +1,10 @@
+2002-03-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/5659
+       * decl.c (xref_tag): Don't set CLASSTYPE_DECLARED_CLASS here.
+       * decl2.c (handle_class_head): Set CLASSTYPE_DECLARED_CLASS for
+       definitions.
+
 2002-03-11  Nathan Sidwell  <nathan@codesourcery.com>
 
        Revert 2001-03-26  Nathan Sidwell  <nathan@codesourcery.com>,
index d7047fcdbfebbb2b57f55114b1dfa706bac7c166..9b5d3e96975bb41e88676ec68483ef0c8bf28b56 100644 (file)
@@ -12858,19 +12858,6 @@ xref_tag (code_type_node, name, globalize)
        redeclare_class_template (ref, current_template_parms);
     }
 
-  /* Until the type is defined, tentatively accept whatever
-     structure tag the user hands us.  */
-  if (!COMPLETE_TYPE_P (ref)
-      && ref != current_class_type
-      /* Have to check this, in case we have contradictory tag info.  */
-      && IS_AGGR_TYPE_CODE (TREE_CODE (ref)))
-    {
-      if (tag_code == class_type)
-       CLASSTYPE_DECLARED_CLASS (ref) = 1;
-      else if (tag_code == record_type)
-       CLASSTYPE_DECLARED_CLASS (ref) = 0;
-    }
-
   TYPE_ATTRIBUTES (ref) = attributes;
 
   return ref;
index 71dc38839ac215fef44a7b6f370143d421c55eb1..8841dec2e2b9870a44a78bd1d087d5e5623ee4d7 100644 (file)
@@ -5252,7 +5252,13 @@ handle_class_head (aggr, scope, id, defn_p, new_type_p)
                     && TREE_CODE (context) != BOUND_TEMPLATE_TEMPLATE_PARM);
       if (*new_type_p)
        push_scope (context);
-  
+
+      if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
+       /* It is legal to define a class with a different class key,
+          and this changes the default member access.  */
+       CLASSTYPE_DECLARED_CLASS (TREE_TYPE (decl))
+         = aggr == class_type_node;
+       
       if (!xrefd_p && PROCESSING_REAL_TEMPLATE_DECL_P ())
        decl = push_template_decl (decl);
     }
index ae6ec906b282771dfbbb3ddd472d8a080f51d529..cde8e627840d51201e6b24afa4f1269e41cf4c93 100644 (file)
@@ -1,3 +1,7 @@
+2002-03-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.dg/other/access1.C: New test.
+
 2002-03-12  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.c-torture/execute/wchar_t-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/other/access1.C b/gcc/testsuite/g++.dg/other/access1.C
new file mode 100644 (file)
index 0000000..ee3239b
--- /dev/null
@@ -0,0 +1,26 @@
+// { dg-do compile }
+
+// Copyright (C) 2002 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 12 Mar 2002 <nathan@codesourcery.com>
+
+// PR c++/5659. Failed to notice default accessed changed
+
+class Foo;
+struct Foo 
+{
+  static int m;
+};
+
+class Outer {
+  private:
+  class Inner;
+  Inner *i;
+  public:
+  void pub();
+};
+
+struct Outer::Inner {
+  Inner(int i);
+};
+
+void Outer::pub() { i = new Inner(Foo::m); }