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 <pola...@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