This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to fix ICE with -Wbool-operation (PR c++/82040)
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Thu, 31 Aug 2017 14:17:54 +0200
- Subject: C++ PATCH to fix ICE with -Wbool-operation (PR c++/82040)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 09233C047B8D
Here we got into re-entering the error reporting routines because the
warning_at call wasn't guarded with "complain", and crash ensued.
Bootstrapped/regtested on x86_64-linux, ok for trunk/7?
2017-08-31 Marek Polacek <polacek@redhat.com>
PR c++/82040
* typeck.c (cp_build_unary_op): Avoid re-entering reporting routines.
* g++.dg/warn/Wbool-operation-1.C: New test.
diff --git gcc/cp/typeck.c gcc/cp/typeck.c
index 171c2dfb57c..b303ceaede1 100644
--- gcc/cp/typeck.c
+++ gcc/cp/typeck.c
@@ -5982,6 +5982,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert,
{
/* Warn if the expression has boolean value. */
if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE
+ && (complain & tf_error)
&& warning_at (location, OPT_Wbool_operation,
"%<~%> on an expression of type bool"))
inform (location, "did you mean to use logical not (%<!%>)?");
diff --git gcc/testsuite/g++.dg/warn/Wbool-operation-1.C gcc/testsuite/g++.dg/warn/Wbool-operation-1.C
index e69de29bb2d..4512b858287 100644
--- gcc/testsuite/g++.dg/warn/Wbool-operation-1.C
+++ gcc/testsuite/g++.dg/warn/Wbool-operation-1.C
@@ -0,0 +1,11 @@
+// PR c++/82040
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wbool-operation" }
+
+template <class c>
+decltype (~c{})
+call ()
+{
+ return ~false; // { dg-warning "on an expression of type bool" }
+}
+template int call<bool>();
Marek