mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-24 03:14:08 +08:00
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:
parent
fa6894ec9c
commit
3a2b12bc5a
@ -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:
|
||||
|
16
gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C
Normal file
16
gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user