From: Marek Polacek Date: Wed, 12 May 2021 15:19:13 +0000 (-0400) Subject: c++: Disable -Wint-in-bool-context in instantiations X-Git-Tag: basepoints/gcc-13~7560 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a2b12bc5a7da7f0c5cf2ef4879d435a02feda8d;p=thirdparty%2Fgcc.git c++: Disable -Wint-in-bool-context in instantiations This warning is of questionable value when it's emitted when instantiating a template, as in the following testcase. It could be silenced by writing hb(i) << 1 instead of 2 * hb(i) but that's unnecessary obfuscation. gcc/cp/ChangeLog: * pt.c (tsubst_copy_and_build): Add warn_int_in_bool_context sentinel. gcc/testsuite/ChangeLog: * g++.dg/warn/Wint-in-bool-context-2.C: New test. --- diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 85c05af42ed4..d7d6a3f2c14a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19801,6 +19801,7 @@ tsubst_copy_and_build (tree t, warning_sentinel s(warn_useless_cast); warning_sentinel s2(warn_ignored_qualifiers); + warning_sentinel s3(warn_int_in_bool_context); switch (TREE_CODE (t)) { case CAST_EXPR: diff --git a/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C new file mode 100644 index 000000000000..6cb482d4dc9b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C @@ -0,0 +1,16 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-Wint-in-bool-context" } + +unsigned hb(unsigned i) { return ~i; } + +template +void f(int i) +{ + auto l = [i]() { return T(2 * hb(i)); }; // { dg-bogus "in boolean context" } + (void) l; +} + +int main() +{ + f(0); +}