diff mbox

C++ PATCH for c++/45378 (missed narrowing error)

Message ID 4DFA7D4D.6000707@redhat.com
State New
Headers show

Commit Message

Jason Merrill June 16, 2011, 10:01 p.m. UTC
Here, reshape_init throws away the CONSTRUCTOR, so we need to call 
check_narrowing before we forget about it.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 25767f0e366840ff8d1c334830785c2cba9c09cc
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jun 15 15:20:18 2011 -0400

    	PR c++/45378
    	* decl.c (check_initializer): Check narrowing.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 3ccefb9..c1e67a7 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5464,7 +5464,11 @@  check_initializer (tree decl, tree init, int flags, tree *cleanup)
 	      init = error_mark_node;
 	    }
 	  else
-	    init = reshape_init (type, init, tf_warning_or_error);	    
+	    {
+	      init = reshape_init (type, init, tf_warning_or_error);
+	      if (cxx_dialect >= cxx0x && SCALAR_TYPE_P (type))
+		check_narrowing (type, init);
+	    }
 	}
 
       /* If DECL has an array type without a specific bound, deduce the
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist52.C b/gcc/testsuite/g++.dg/cpp0x/initlist52.C
new file mode 100644
index 0000000..22bc287
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist52.C
@@ -0,0 +1,7 @@ 
+// PR c++/45378
+// { dg-options -std=c++0x }
+
+int main()
+{
+   int x { 22.2 };		// { dg-error "narrowing" }
+}