From: Paolo Carlini Date: Fri, 4 Nov 2016 18:58:53 +0000 (+0000) Subject: re PR c++/67980 (left shift count is negative [-Wshift-count-negative] generated... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e3ae7e6f5699430cdedd1ca2a7b5cfa020171aa;p=gcc.git re PR c++/67980 (left shift count is negative [-Wshift-count-negative] generated for unreachable code) /cp 2016-11-04 Paolo Carlini PR c++/67980 * pt.c (tsubst_expr, case IF_STMT): Use fold_non_dependent_expr to suppress unwanted warnings. /testsuite 2016-11-04 Paolo Carlini PR c++/67980 * g++.dg/cpp1y/pr67980.C: New. From-SVN: r241858 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 544de43479f..e567fefd627 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-11-04 Paolo Carlini + + PR c++/67980 + * pt.c (tsubst_expr, case IF_STMT): Use fold_non_dependent_expr + to suppress unwanted warnings. + 2016-11-03 Jason Merrill PR c++/78198 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e5134487816..c8d4a066c5d 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15437,15 +15437,27 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, if (IF_STMT_CONSTEXPR_P (t) && integer_zerop (tmp)) /* Don't instantiate the THEN_CLAUSE. */; else - RECUR (THEN_CLAUSE (t)); + { + bool inhibit = integer_zerop (fold_non_dependent_expr (tmp)); + if (inhibit) + ++c_inhibit_evaluation_warnings; + RECUR (THEN_CLAUSE (t)); + if (inhibit) + --c_inhibit_evaluation_warnings; + } finish_then_clause (stmt); if (IF_STMT_CONSTEXPR_P (t) && integer_nonzerop (tmp)) /* Don't instantiate the ELSE_CLAUSE. */; else if (ELSE_CLAUSE (t)) { + bool inhibit = integer_nonzerop (fold_non_dependent_expr (tmp)); begin_else_clause (stmt); + if (inhibit) + ++c_inhibit_evaluation_warnings; RECUR (ELSE_CLAUSE (t)); + if (inhibit) + --c_inhibit_evaluation_warnings; finish_else_clause (stmt); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 910b8d2f5f3..eae75f1c453 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-04 Paolo Carlini + + PR c++/67980 + * g++.dg/cpp1y/pr67980.C: New. + 2016-11-04 Bill Schmidt * gcc.target/powerpc/fold-vec-add-1.c: New. diff --git a/gcc/testsuite/g++.dg/cpp1y/pr67980.C b/gcc/testsuite/g++.dg/cpp1y/pr67980.C new file mode 100644 index 00000000000..1b8154538fc --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr67980.C @@ -0,0 +1,23 @@ +// { dg-do compile { target c++14 } } + +template +constexpr T cpp14_constexpr_then(T value) { + if (Y < 0) + return (value << -Y); + else + return 0; +} + +template +constexpr T cpp14_constexpr_else(T value) { + if (Y > 0) + return 0; + else + return (value << -Y); +} + +int main() +{ + cpp14_constexpr_then<1>(0); + cpp14_constexpr_else<1>(0); +}