From 72f382fbb85a77a75e839077a7df59197799e2f4 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Tue, 24 May 2016 16:41:39 +0000 Subject: [PATCH] re PR c++/69872 (-Wnarrowing note without warning/errror) /cp 2016-05-24 Paolo Carlini PR c++/69872 * typeck2.c (check_narrowing): Check pedwarn return value. /testsuite 2016-05-24 Paolo Carlini PR c++/69872 * g++.dg/warn/Wno-narrowing1.C: New. From-SVN: r236651 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck2.c | 10 ++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/Wno-narrowing1.C | 7 +++++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wno-narrowing1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c77dee6dfb7..4e06a71e7ca 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2016-05-24 Paolo Carlini + + PR c++/69872 + * typeck2.c (check_narrowing): Check pedwarn return value. + 2016-05-24 Jakub Jelinek PR c++/71257 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 833be20f7fe..835a44f1cf6 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -950,10 +950,12 @@ check_narrowing (tree type, tree init, tsubst_flags_t complain) { if (complain & tf_warning_or_error) { - if (!almost_ok || pedantic) - pedwarn (loc, OPT_Wnarrowing, "narrowing conversion of %qE " - "from %qT to %qT inside { }", init, ftype, type); - if (pedantic && almost_ok) + if ((!almost_ok || pedantic) + && pedwarn (loc, OPT_Wnarrowing, + "narrowing conversion of %qE " + "from %qT to %qT inside { }", + init, ftype, type) + && almost_ok) inform (loc, " the expression has a constant value but is not " "a C++ constant-expression"); ok = true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e2b2466903c..d27369c87f5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-24 Paolo Carlini + + PR c++/69872 + * g++.dg/warn/Wno-narrowing1.C: New. + 2016-05-24 Marek Polacek PR c/71249 diff --git a/gcc/testsuite/g++.dg/warn/Wno-narrowing1.C b/gcc/testsuite/g++.dg/warn/Wno-narrowing1.C new file mode 100644 index 00000000000..285f05a1249 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wno-narrowing1.C @@ -0,0 +1,7 @@ +// PR c++/69872 +// { dg-options "-Wall -Wextra -pedantic -Wno-narrowing" } + +struct s { int x, y; }; +short offsets[1] = { + ((char*) &(((struct s*)16)->y) - (char *)16), // { dg-bogus "note" } +}; -- 2.30.2