Bug 51214 - [4.7 Regression] [C++11] name lookup issue with c++11 enums
Summary: [4.7 Regression] [C++11] name lookup issue with c++11 enums
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P2 normal
Target Milestone: 4.7.2
Assignee: fabien
URL:
Keywords: rejects-valid
Depends on: 53995
Blocks:
  Show dependency treegraph
 
Reported: 2011-11-18 20:10 UTC by fabien
Modified: 2012-07-17 11:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.2
Known to fail: 4.7.0
Last reconfirmed: 2011-11-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fabien 2011-11-18 20:10:27 UTC
Noticed while working on PR c++/51188, I have launched the c++ testsuite with the patch below:
Index: class.c
===================================================================
--- class.c	(revision 181491)
+++ class.c	(working copy)
@@ -6007,7 +6007,7 @@ finish_struct_1 (tree t)
      hierarchy), and we want this failure to occur quickly.  */
 
   n_fields = count_fields (TYPE_FIELDS (t));
-  if (n_fields > 7)
+  if (n_fields > 0)
     
And it has raised two errors related to c++11 enums: forw_enum5.C and forw_enum9.C. Thus, here is a reproducer, comming from forw_enum5.C:

// { dg-do compile }
// { dg-options "-std=c++0x" }

namespace one
{
    struct S
    {
        enum { A = 1, B = 2 };
        struct T
        {
	    int i1, i2, i3, i4, i5, i6, i7;

            enum { B = 102 };

            enum class E1;
            enum E2 : int;
        };
    };

    static_assert(int(S::T::A1) == 1, "error");
    static_assert(int(S::T::B1) == 102, "error");
    static_assert(int(S::T::C1) == 103, "error");
}

The following errors are issued:

error: 'A1' is not a member of 'one::S::T'

error: 'B1' is not a member of 'one::S::T'

error: 'C1' is not a member of 'one::S::T'


Most likely an issue in the sorted case of lookup_field_1. Mine.
Comment 1 fabien 2011-12-29 20:02:15 UTC
Here is a correct testcase for this bug.

// { dg-do compile }
// { dg-options "-std=c++0x" }

enum { A = 1 };
struct T
{
    int i1, i2, i3, i4, i5, i6, i7;
    enum E2 : int;
};

enum T::E2 : int { A1 = A };
int i = T::A1;
Comment 2 fabien 2012-02-28 20:19:23 UTC
We can manage to mark this bug as a 4.7 Regression, evidence below (to be compiled with -std=c++11 obviously).

struct Base
{
    int b1, b2, b3;
};

struct T : Base
{
    int t1, t2, t3;

    using Base::b1;
    using Base::b2;
    using Base::b3;

    enum E2 : int;
};

enum T::E2 : int { A1 = 23 };
int i = T::A1;

I have a patch for it.
Comment 3 fabien 2012-06-07 05:36:23 UTC
Author: fabien
Date: Thu Jun  7 05:36:18 2012
New Revision: 188294

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188294
Log:
gcc/testsuite/ChangeLog

2012-06-07  Fabien Chêne  <fabien@gcc.gnu.org>

	PR c++/51214
	* g++.dg/cpp0x/forw_enum11.C: New.

gcc/cp/ChangeLog

2012-06-07  Fabien Chêne  <fabien@gcc.gnu.org>

	PR c++/51214
	* cp-tree.h (insert_late_enum_def_into_classtype_sorted_fields):
	Declare.
	* class.c (insert_into_classtype_sorted_fields): New.
	(add_enum_fields_to_record_type): New.
	(count_fields): Adjust the comment.
	(add_fields_to_record_type): Likewise.
	(finish_struct_1): Move the code that inserts the fields for the
	sorted case, into insert_into_classtype_sorted_fields, and call
	it.
	(insert_late_enum_def_into_classtype_sorted_fields): Define.
	* decl.c (finish_enum_value_list): Call
	insert_late_enum_def_into_classtype_sorted_fields if a late enum
	definition is encountered.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/forw_enum11.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/class.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2012-06-07 19:53:40 UTC
Fixed on trunk.
Comment 5 Richard Biener 2012-06-14 08:30:23 UTC
GCC 4.7.1 is being released, adjusting target milestone.
Comment 6 fabien 2012-06-27 17:36:56 UTC
Author: fabien
Date: Wed Jun 27 17:36:50 2012
New Revision: 189021

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189021
Log:
gcc/testsuite/ChangeLog

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

	PR c++/51214
	* g++.dg/cpp0x/forw_enum11.C: New.

gcc/cp/ChangeLog

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

	PR c++/51214
	* cp-tree.h (insert_late_enum_def_into_classtype_sorted_fields):
	Declare.
	* class.c (insert_into_classtype_sorted_fields): New.
	(add_enum_fields_to_record_type): New.
	(count_fields): Adjust the comment.
	(add_fields_to_record_type): Likewise.
	(finish_struct_1): Move the code that inserts the fields for the
	sorted case, into insert_into_classtype_sorted_fields, and call
	it.
	(insert_late_enum_def_into_classtype_sorted_fields): Define.
	* decl.c (finish_enum_value_list): Call
	insert_late_enum_def_into_classtype_sorted_fields if a late enum
	definition is encountered.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/forw_enum11.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/class.c
    branches/gcc-4_7-branch/gcc/cp/cp-tree.h
    branches/gcc-4_7-branch/gcc/cp/decl.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 7 fabien 2012-06-27 17:53:11 UTC
Fixed in 4.7.