From f5322614a6fb5a0ce3cf85914e85946296271e91 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 4 May 2015 20:58:33 +0000 Subject: [PATCH] re PR c++/66007 (Narrowing conversion inside { } results in all zero elements in C++11 mode with -Wno-error=narrowing) /cp 2015-05-04 Paolo Carlini Jakub Jelinek PR c++/66007 * typeck2.c (check_narrowing): Check by-hand that the pedwarn didn't result in an actual error. /testsuite 2015-05-04 Paolo Carlini Jakub Jelinek PR c++/66007 * g++.dg/cpp0x/Wnarrowing4.C: New. Co-Authored-By: Jakub Jelinek From-SVN: r222778 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/typeck2.c | 8 +++++--- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 65cb5bee27b..bd9f2f32776 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2015-05-04 Paolo Carlini + Jakub Jelinek + + PR c++/66007 + * typeck2.c (check_narrowing): Check by-hand that the pedwarn didn't + result in an actual error. + 2015-05-01 Paolo Carlini Prathamesh Kulharni diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 9a491aa71f2..c0df8237a12 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -958,10 +958,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) } else if (complain & tf_error) { + int savederrorcount = errorcount; global_dc->pedantic_errors = 1; - if (!pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing, - "narrowing conversion of %qE from %qT to %qT " - "inside { }", init, ftype, type)) + pedwarn (EXPR_LOC_OR_LOC (init, input_location), OPT_Wnarrowing, + "narrowing conversion of %qE from %qT to %qT " + "inside { }", init, ftype, type); + if (errorcount == savederrorcount) ok = true; global_dc->pedantic_errors = flag_pedantic_errors; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3673938aab0..a73ad283490 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-05-04 Paolo Carlini + Jakub Jelinek + + PR c++/66007 + * g++.dg/cpp0x/Wnarrowing4.C: New. + 2015-05-04 Sandra Loosemore * lib/target-supports.exp diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C new file mode 100644 index 00000000000..7defce3ce89 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing4.C @@ -0,0 +1,14 @@ +// PR c++/66007 +// { dg-do run { target c++11 } } +// { dg-options "-Wno-error=narrowing" } + +extern "C" void abort(); + +int main() +{ + unsigned foo[] = { 1, -1, 3 }; + if (foo[0] != 1 || foo[1] != __INT_MAX__ * 2U + 1 || foo[2] != 3) + abort(); +} + +// { dg-prune-output "narrowing conversion" } -- 2.30.2