From patchwork Thu Jun 16 22:01:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/45378 (missed narrowing error) Date: Thu, 16 Jun 2011 12:01:49 -0000 From: Jason Merrill X-Patchwork-Id: 100733 Message-Id: <4DFA7D4D.6000707@redhat.com> To: gcc-patches List 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. commit 25767f0e366840ff8d1c334830785c2cba9c09cc Author: Jason Merrill 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" } +}