From: Marek Polacek Date: Fri, 10 Feb 2017 16:33:45 +0000 (+0000) Subject: re PR c++/79184 (-Wint-in-bool-context triggered erroneously in template parameter) X-Git-Tag: upstream/12.2.0~41254 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3799a5b853ef08d781407009427f9ddc9a6ec7be;p=platform%2Fupstream%2Fgcc.git re PR c++/79184 (-Wint-in-bool-context triggered erroneously in template parameter) PR c++/79184 * cvt.c (ocp_convert): Add a sentinel against -Wint-in-bool-context if warnings shouldn't be given. * g++.dg/warn/Wint-in-bool-context-1.C: New. From-SVN: r245335 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7f113ec..5ea0c93 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -4,6 +4,10 @@ * pt.c (type_dependent_expression_p): Check if the expression type is null. + PR c++/79184 + * cvt.c (ocp_convert): Add a sentinel against -Wint-in-bool-context + if warnings shouldn't be given. + 2017-02-10 Paolo Carlini PR c++/71737 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index ae9991a..5f4b5e3 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -798,7 +798,15 @@ ocp_convert (tree type, tree expr, int convtype, int flags, to the underlying type first. */ if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) e = build_nop (ENUM_UNDERLYING_TYPE (intype), e); - return cp_truthvalue_conversion (e); + if (complain & tf_warning) + return cp_truthvalue_conversion (e); + else + { + /* Prevent bogus -Wint-in-bool-context warnings coming + from c_common_truthvalue_conversion down the line. */ + warning_sentinel w (warn_int_in_bool_context); + return cp_truthvalue_conversion (e); + } } converted = convert_to_integer_maybe_fold (type, e, dofold); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0c17a036..aab9ef5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ PR c++/79435 * g++.dg/cpp1y/pr79435.C: New. + PR c++/79184 + * g++.dg/warn/Wint-in-bool-context-1.C: New. + 2017-02-10 Christophe Lyon * gcc.target/aarch64/advsimd-intrinsics/p64_p128.c diff --git a/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-1.C b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-1.C new file mode 100644 index 0000000..117eca4 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-1.C @@ -0,0 +1,16 @@ +// PR c++/79184 +// { dg-do compile } +// { dg-options "-Wint-in-bool-context" } + +enum { E = 2 }; +template void f(int) { } +template void f() {} + +int +main () +{ + f<1 * 1>(); // { dg-bogus "in boolean context" } + f<1 << 1>(); // { dg-bogus "in boolean context" } + f<1 ? 3 : 2>(); // { dg-bogus "in boolean context" } + f(); // { dg-bogus "in boolean context" } +}