aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2021-05-12 11:19:13 -0400
committerMarek Polacek <polacek@redhat.com>2021-05-12 13:06:28 -0400
commit3a2b12bc5a7da7f0c5cf2ef4879d435a02feda8d (patch)
tree2407ce65a6581f1fac2fff5020ab9d31901dd893 /gcc
parentfa6894ec9ce25f5aff10ec176212383f5c88b1ec (diff)
downloadgcc-3a2b12bc5a7da7f0c5cf2ef4879d435a02feda8d.zip
gcc-3a2b12bc5a7da7f0c5cf2ef4879d435a02feda8d.tar.gz
gcc-3a2b12bc5a7da7f0c5cf2ef4879d435a02feda8d.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.c1
-rw-r--r--gcc/testsuite/g++.dg/warn/Wint-in-bool-context-2.C16
2 files changed, 17 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 85c05af..d7d6a3f 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 0000000..6cb482d
--- /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<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);
+}