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.
This commit is contained in:
Marek Polacek 2021-05-12 11:19:13 -04:00
parent fa6894ec9c
commit 3a2b12bc5a
2 changed files with 17 additions and 0 deletions

View File

@ -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:

View File

@ -0,0 +1,16 @@
// { dg-do compile { target c++11 } }
// { dg-options "-Wint-in-bool-context" }
unsigned hb(unsigned i) { return ~i; }
template<typename T>
void f(int i)
{
auto l = [i]() { return T(2 * hb(i)); }; // { dg-bogus "in boolean context" }
(void) l;
}
int main()
{
f<bool>(0);
}