diff mbox

C++ PATCH for c++/65554 (ICE with user-defined initializer_list)

Message ID 20150401100816.GQ25731@redhat.com
State New
Headers show

Commit Message

Marek Polacek April 1, 2015, 10:08 a.m. UTC
On Tue, Mar 31, 2015 at 03:11:24PM -0400, Jason Merrill wrote:
> On 03/31/2015 01:22 PM, Marek Polacek wrote:
> >The user *should* have been using <initializer_list>.  But responding to this
> >with an ICE isn't acceptable either.
> >
> >We do reject wholly incompatible user-defined initializer_list: finish_struct
> >requires it be a template with a pointer field followed by an integer field,
> >and in this case it is, but convert_like_real assumes that the second integer
> >field has a size_type, so it initializes the length with that type.  But as the
> >following testcase (which clang accepts) shows, it might be a different integer
> >type, and gimplifier doesn't like any non-trivial conversion in an assignment.
> 
> I think I'd prefer to enforce that the second integer is size_t, not just an
> integer, so that the assumption in convert_like_real is correct.

Ok, that isn't hard to do either.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2015-04-01  Marek Polacek  <polacek@redhat.com>

	PR c++/65554
	* class.c (finish_struct): Require that the second field of a
	user-defined initializer_list be of size type.

	* g++.dg/cpp0x/initlist93.C: New test.
	* g++.dg/cpp0x/initlist94.C: New test.


	Marek

Comments

Jason Merrill April 1, 2015, 12:42 p.m. UTC | #1
OK, thanks.

Jason
H.J. Lu April 1, 2015, 10:37 p.m. UTC | #2
On Wed, Apr 1, 2015 at 3:08 AM, Marek Polacek <polacek@redhat.com> wrote:
> On Tue, Mar 31, 2015 at 03:11:24PM -0400, Jason Merrill wrote:
>> On 03/31/2015 01:22 PM, Marek Polacek wrote:
>> >The user *should* have been using <initializer_list>.  But responding to this
>> >with an ICE isn't acceptable either.
>> >
>> >We do reject wholly incompatible user-defined initializer_list: finish_struct
>> >requires it be a template with a pointer field followed by an integer field,
>> >and in this case it is, but convert_like_real assumes that the second integer
>> >field has a size_type, so it initializes the length with that type.  But as the
>> >following testcase (which clang accepts) shows, it might be a different integer
>> >type, and gimplifier doesn't like any non-trivial conversion in an assignment.
>>
>> I think I'd prefer to enforce that the second integer is size_t, not just an
>> integer, so that the assumption in convert_like_real is correct.
>
> Ok, that isn't hard to do either.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2015-04-01  Marek Polacek  <polacek@redhat.com>
>
>         PR c++/65554
>         * class.c (finish_struct): Require that the second field of a
>         user-defined initializer_list be of size type.
>
>         * g++.dg/cpp0x/initlist93.C: New test.
>         * g++.dg/cpp0x/initlist94.C: New test.
>

This caused:

FAIL: g++.dg/cpp0x/pr57101.C  -std=gnu++11 (test for excess errors)
FAIL: g++.dg/cpp0x/pr57101.C  -std=gnu++14 (test for excess errors)

on 32 bit system.
Marek Polacek April 2, 2015, 8:28 a.m. UTC | #3
On Wed, Apr 01, 2015 at 03:37:19PM -0700, H.J. Lu wrote:
> This caused:
> 
> FAIL: g++.dg/cpp0x/pr57101.C  -std=gnu++11 (test for excess errors)
> FAIL: g++.dg/cpp0x/pr57101.C  -std=gnu++14 (test for excess errors)
> 
> on 32 bit system.

Thanks, I'll fix it momentarily.
diff mbox

Patch

diff --git gcc/cp/class.c gcc/cp/class.c
index c2d4201..9f189fb 100644
--- gcc/cp/class.c
+++ gcc/cp/class.c
@@ -6891,7 +6891,7 @@  finish_struct (tree t, tree attributes)
 	  if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE)
 	    {
 	      f = next_initializable_field (DECL_CHAIN (f));
-	      if (f && TREE_CODE (TREE_TYPE (f)) == INTEGER_TYPE)
+	      if (f && same_type_p (TREE_TYPE (f), size_type_node))
 		ok = true;
 	    }
 	}
diff --git gcc/testsuite/g++.dg/cpp0x/initlist93.C gcc/testsuite/g++.dg/cpp0x/initlist93.C
index e69de29..84a4738 100644
--- gcc/testsuite/g++.dg/cpp0x/initlist93.C
+++ gcc/testsuite/g++.dg/cpp0x/initlist93.C
@@ -0,0 +1,13 @@ 
+// PR c++/65554
+// { dg-do compile { target c++11 } }
+
+namespace std
+{
+template <class> class initializer_list // { dg-error "definition of std::initializer_list does not match" }
+{
+  int *_M_array;
+  int _M_len;
+};
+}
+
+// { dg-prune-output "compilation terminated" }
diff --git gcc/testsuite/g++.dg/cpp0x/initlist94.C gcc/testsuite/g++.dg/cpp0x/initlist94.C
index e69de29..f83a81d 100644
--- gcc/testsuite/g++.dg/cpp0x/initlist94.C
+++ gcc/testsuite/g++.dg/cpp0x/initlist94.C
@@ -0,0 +1,13 @@ 
+// PR c++/65554
+// { dg-do compile { target c++11 } }
+
+typedef decltype (sizeof (int)) size_type;
+
+namespace std
+{
+template <class> class initializer_list
+{
+  int *_M_array;
+  size_type _M_len;
+};
+}