public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: C++ PATCH to fix ICE with -Wbool-operation (PR c++/82040)
Date: Thu, 31 Aug 2017 14:03:00 -0000	[thread overview]
Message-ID: <20170831121754.GH17069@redhat.com> (raw)

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

             reply	other threads:[~2017-08-31 12:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 14:03 Marek Polacek [this message]
2017-08-31 18:57 ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170831121754.GH17069@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).