From 76f86d00d99168e75b27d8e641844237c78ad102 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 22 Jul 2011 20:14:46 -0400 Subject: [PATCH] re PR c++/49793 ([C++0x] Narrowing conversion from int/short/char to double) PR c++/49793 * typeck2.c (check_narrowing): Downgrade permerror to pedwarn. Make conditional on -Wnarrowing. From-SVN: r176665 --- gcc/c-family/ChangeLog | 3 +++ gcc/c-family/c.opt | 4 ++++ gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck2.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/initlist17.C | 2 +- gcc/testsuite/g++.dg/cpp0x/initlist36.C | 2 +- gcc/testsuite/g++.dg/cpp0x/initlist5.C | 2 +- gcc/testsuite/g++.dg/cpp0x/initlist52.C | 2 +- gcc/testsuite/g++.dg/cpp0x/initlist7.C | 2 +- 10 files changed, 26 insertions(+), 8 deletions(-) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 990302f17ce..be7317d0eb2 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,8 @@ 2011-07-22 Jason Merrill + PR c++/49793 + * c.opt (Wnarrowing): New. + PR c++/30112 * c-common.h: Declare c_linkage_bindings. * c-pragma.c (handle_pragma_redefine_extname): Use it. diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 00bdd93f124..617ea2d8905 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -489,6 +489,10 @@ Wmultichar C ObjC C++ ObjC++ Warning Warn about use of multi-character character constants +Wnarrowing +C ObjC C++ ObjC++ Warning Var(warn_narrowing) Init(1) +-Wno-narrowing In C++0x mode, ignore ill-formed narrowing conversions within { } + Wnested-externs C ObjC Var(warn_nested_externs) Warning Warn about \"extern\" declarations not at file scope diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index cdbb3fe5ecb..284224f57c6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-07-22 Jason Merrill + + PR c++/49793 + * typeck2.c (check_narrowing): Downgrade permerror to pedwarn. + Make conditional on -Wnarrowing. + 2011-07-22 Ville Voutilainen Warn about the use of final/override in non-c++0x mode, and diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index bdd2452ffe1..727a88bd363 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -719,7 +719,7 @@ check_narrowing (tree type, tree init) bool ok = true; REAL_VALUE_TYPE d; - if (!ARITHMETIC_TYPE_P (type)) + if (!warn_narrowing || !ARITHMETIC_TYPE_P (type)) return; if (BRACE_ENCLOSED_INITIALIZER_P (init) @@ -777,8 +777,8 @@ check_narrowing (tree type, tree init) } if (!ok) - permerror (input_location, "narrowing conversion of %qE from %qT " - "to %qT inside { }", init, ftype, type); + pedwarn (input_location, OPT_Wnarrowing, "narrowing conversion of %qE " + "from %qT to %qT inside { }", init, ftype, type); } /* Process the initializer INIT for a variable of type TYPE, emitting diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a364c72a7e4..1d0d08952c5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-07-22 Jason Merrill + + PR c++/49793 + * g++.dg/cpp0x/initlist55.C: New. + 2011-07-23 Tobias Burnus PR fortran/49791 diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist17.C b/gcc/testsuite/g++.dg/cpp0x/initlist17.C index 86371e81969..6ea08d15003 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist17.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist17.C @@ -1,4 +1,4 @@ -// { dg-options "-std=c++0x" } +// { dg-options "-std=c++0x -pedantic-errors" } void f(int i); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist36.C b/gcc/testsuite/g++.dg/cpp0x/initlist36.C index 94624c977c9..a703b45907e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist36.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist36.C @@ -1,5 +1,5 @@ // PR c++/44358 -// { dg-options "-std=c++0x" } +// { dg-options "-std=c++0x -pedantic-errors" } #include diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist5.C b/gcc/testsuite/g++.dg/cpp0x/initlist5.C index 32caac38251..dbd17ecbbe2 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist5.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist5.C @@ -1,5 +1,5 @@ // Test for narrowing diagnostics -// { dg-options "-std=c++0x" } +// { dg-options "-std=c++0x -pedantic-errors" } #include diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist52.C b/gcc/testsuite/g++.dg/cpp0x/initlist52.C index 22bc2873c7c..17c0cfe3f14 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist52.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist52.C @@ -1,5 +1,5 @@ // PR c++/45378 -// { dg-options -std=c++0x } +// { dg-options "-std=c++0x -pedantic-errors" } int main() { diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist7.C b/gcc/testsuite/g++.dg/cpp0x/initlist7.C index 7913ed7edb1..55a0371860f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist7.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist7.C @@ -1,5 +1,5 @@ // PR c++/37932 -// { dg-options "-std=c++0x" } +// { dg-options "-std=c++0x -pedantic-errors" } typedef enum { AA=1, BB=2 } my_enum; -- 2.30.2