public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ Patch] for c++/51214
@ 2012-02-28 20:57 Fabien Chêne
  2012-02-28 22:06 ` Paolo Carlini
  2012-02-28 23:22 ` Jason Merrill
  0 siblings, 2 replies; 17+ messages in thread
From: Fabien Chêne @ 2012-02-28 20:57 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

Hi,

The problem in this PR is that the CLASSTYPE_SORTED_FIELDS is created
too early (in finish_struct_1) to handle those "late" unscoped enum
definitions.
Consequently, I propose to lately add those names in
CLASSTYPE_SORTED_FIELDS when they are encountered, in
build_enumerator.

Tested x86_64-unknown-linux-gnu, OK for 4.7 ?

gcc/testsuite/ChangeLog

2012-02-27  Fabien Chêne  <fabien@gcc.gnu.org>

	* g++.dg/cpp0x/forw_enum11.C: New.

gcc/cp/ChangeLog

2012-02-27  Fabien Chêne  <fabien@gcc.gnu.org>

	* cp-tree.h (insert_into_classtype_sorted_fields): Declare.
	* class.c (finish_struct_1): Move the code into
	insert_into_classtype_sorted_fields, and call it.
	(insert_into_classtype_sorted_fields): Define.
	* decl.c (build_enumerator): Call
	insert_into_classtype_sorted_fields if an enumerator-definition referring
	to a class scope opaque enum has been encountered.

-- 
Fabien

[-- Attachment #2: 51214.patch --]
[-- Type: application/octet-stream, Size: 3562 bytes --]

Index: gcc/testsuite/g++.dg/cpp0x/forw_enum11.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/forw_enum11.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/forw_enum11.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+enum { A = 1 };
+struct T
+{
+    int i1, i2, i3, i4, i5, i6, i7;
+    enum E2 : int;
+};
+
+enum T::E2 : int { A1 = A, A2 = 23 };
+int i = T::A1;
+int j = T::A2;
Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c	(revision 184327)
+++ gcc/cp/class.c	(working copy)
@@ -5954,7 +5954,6 @@ finish_struct_1 (tree t)
   tree x;
   /* A TREE_LIST.  The TREE_VALUE of each node is a FUNCTION_DECL.  */
   tree virtuals = NULL_TREE;
-  int n_fields = 0;
 
   if (COMPLETE_TYPE_P (t))
     {
@@ -6071,16 +6070,7 @@ finish_struct_1 (tree t)
      We use a small number because most searches fail (succeeding
      ultimately as the search bores through the inheritance
      hierarchy), and we want this failure to occur quickly.  */
-
-  n_fields = count_fields (TYPE_FIELDS (t));
-  if (n_fields > 7)
-    {
-      struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields);
-      add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
-      qsort (field_vec->elts, n_fields, sizeof (tree),
-	     field_decl_cmp);
-      CLASSTYPE_SORTED_FIELDS (t) = field_vec;
-    }
+  insert_into_classtype_sorted_fields (TYPE_FIELDS (t), t, 8);
 
   /* Complain if one of the field types requires lower visibility.  */
   constrain_class_visibility (t);
@@ -6153,6 +6143,22 @@ finish_struct_1 (tree t)
     }
 }
 
+/* Insert FIELDS into T for the sorted case if the FIELDS count is
+   equal to THREASHOLD or greater than THREASHOLD.  */
+
+void insert_into_classtype_sorted_fields (tree fields, tree t, int threashold)
+{
+  int n_fields = count_fields (fields);
+  if (n_fields >= threashold)
+    {
+      struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields);
+      add_fields_to_record_type (fields, field_vec, 0);
+      qsort (field_vec->elts, n_fields, sizeof (tree), field_decl_cmp);
+      CLASSTYPE_SORTED_FIELDS (t) = field_vec;
+    }
+}
+
+
 /* When T was built up, the member declarations were added in reverse
    order.  Rearrange them to declaration order.  */
 
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 184328)
+++ gcc/cp/decl.c	(working copy)
@@ -12517,7 +12517,12 @@ incremented enumerator value is too larg
     /* In something like `struct S { enum E { i = 7 }; };' we put `i'
        on the TYPE_FIELDS list for `S'.  (That's so that you can say
        things like `S::i' later.)  */
-    finish_member_declaration (decl);
+    {
+      finish_member_declaration (decl);
+      if (COMPLETE_TYPE_P (current_class_type)
+	  && UNSCOPED_ENUM_P (enumtype))
+	insert_into_classtype_sorted_fields (decl, current_class_type, 0);
+    }
   else
     pushdecl (decl);
 
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 184327)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -4969,6 +4969,7 @@ extern void fixup_attribute_variants		(t
 extern tree* decl_cloned_function_p		(const_tree, bool);
 extern void clone_function_decl			(tree, int);
 extern void adjust_clone_args			(tree);
+extern void insert_into_classtype_sorted_fields (tree, tree, int);
 
 /* in cvt.c */
 extern tree convert_to_reference		(tree, tree, int, int, tree);

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-07-17 11:57 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28 20:57 [C++ Patch] for c++/51214 Fabien Chêne
2012-02-28 22:06 ` Paolo Carlini
2012-02-28 23:22 ` Jason Merrill
2012-02-28 23:28   ` Fabien Chêne
2012-02-29  7:56     ` Fabien Chêne
2012-02-29 15:31     ` Jason Merrill
2012-05-06 20:07       ` Fabien Chêne
2012-05-07 14:41         ` Jason Merrill
2012-05-23 20:38           ` Fabien Chêne
2012-05-24 13:18             ` Jason Merrill
2012-06-03  4:47               ` Jason Merrill
2012-06-03 15:56                 ` Fabien Chêne
2012-06-03 17:06                   ` Gabriel Dos Reis
2012-06-04 12:41                     ` Fabien Chêne
2012-06-07  5:40                   ` Fabien Chêne
2012-06-27 18:26                     ` Fabien Chêne
2012-07-17 11:57                       ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).