]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Disable -Wint-in-bool-context in instantiations
authorMarek Polacek <polacek@redhat.com>
Wed, 12 May 2021 15:19:13 +0000 (11:19 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 12 May 2021 17:06:28 +0000 (13:06 -0400)
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.

gcc/cp/pt.c
gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C [new file with mode: 0644]

index 85c05af42ed4d92428de76f6831f0b948704c8ab..d7d6a3f2c14a2017ceb6c68e84746df8bc51d347 100644 (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:
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 (file)
index 0000000..6cb482d
--- /dev/null
@@ -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);
+}