diff mbox

[C++] Fix PR58705

Message ID 20131024134243.GD27400@redhat.com
State New
Headers show

Commit Message

Marek Polacek Oct. 24, 2013, 1:42 p.m. UTC
On Thu, Oct 24, 2013 at 09:16:05AM -0400, Jason Merrill wrote:
> On 10/14/2013 08:23 AM, Marek Polacek wrote:
> >We were ICEing on the attached testcase, because in check_narrowing,
> >for = {{}}, we wanted to check recursively the CONSTRUCTOR_ELTs,
> >even though init in this case has 0 CONSTRUCTOR_NELTS.  So I added
> >the check for CONSTRUCTOR_NELTS > 0.  Moreover, since empty scalar
> >initializers are forbidden in C FE, I think we should error out here
> >too.  (Complex type is considered as an arithmetic type as a GNU
> >extension and arithmetic types are scalar types.)
> 
> Empty scalar initializers are allowed in C++11, so we shouldn't give
> an error.  Your initial patch from bugzilla is OK, with an
> appropriately adjusted testcase.

Thanks, will commit the following.

2013-10-24  Marek Polacek  <polacek@redhat.com>

	PR c++/58705
cp/
	* typeck2.c (check_narrowing): Don't check narrowing when the scalar
	initializer is empty.
testsuite/
	* g++.dg/parse/pr58705.C: New test.


	Marek
diff mbox

Patch

--- gcc/cp/typeck2.c.mp	2013-10-24 15:34:39.225244689 +0200
+++ gcc/cp/typeck2.c	2013-10-24 15:37:19.045825247 +0200
@@ -834,7 +834,8 @@  check_narrowing (tree type, tree init)
       && TREE_CODE (type) == COMPLEX_TYPE)
     {
       tree elttype = TREE_TYPE (type);
-      check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value);
+      if (CONSTRUCTOR_NELTS (init) > 0)
+        check_narrowing (elttype, CONSTRUCTOR_ELT (init, 0)->value);
       if (CONSTRUCTOR_NELTS (init) > 1)
 	check_narrowing (elttype, CONSTRUCTOR_ELT (init, 1)->value);
       return;
--- gcc/testsuite/g++.dg/parse/pr58705.C.mp	2013-10-24 15:38:41.023132022 +0200
+++ gcc/testsuite/g++.dg/parse/pr58705.C	2013-10-24 15:38:25.035071911 +0200
@@ -0,0 +1,5 @@ 
+// PR c++/58705
+// { dg-do compile }
+// { dg-options "-Wnarrowing" }
+
+_Complex float f = {{}};