This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77434] warn about suspicious precedence of ternary operator (?:)
- From: "bernd.edlinger at hotmail dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 03 Sep 2016 14:09:10 +0000
- Subject: [Bug c++/77434] warn about suspicious precedence of ternary operator (?:)
- Auto-submitted: auto-generated
- References: <bug-77434-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77434
--- Comment #11 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
As I said, I think "<<" on signed integers is generally bogus in a
truth value context.
So I tried an experiment for such a warning:
Index: c-common.c
===================================================================
--- c-common.c (Revision 239953)
+++ c-common.c (Arbeitskopie)
@@ -4601,6 +4601,13 @@ c_common_truthvalue_conversion (location_t locatio
/* These don't change whether an object is nonzero or zero. */
return c_common_truthvalue_conversion (location, TREE_OPERAND (expr,
0));
+ case LSHIFT_EXPR:
+ if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE
+ && !TYPE_UNSIGNED (TREE_TYPE (expr)))
+ warning_at (EXPR_LOCATION (expr), 0,
+ "<< on signed integer in boolean context");
+ break;
+
case LROTATE_EXPR:
case RROTATE_EXPR:
/* These don't change whether an object is zero or nonzero, but
And guess what: it immediately found something!
In file included from ../../gcc-trunk/gcc/cp/parser.c:24:0:
../../gcc-trunk/gcc/cp/parser.c: In function 'tree_node*
cp_parser_condition(cp_parser*)':
../../gcc-trunk/gcc/cp/cp-tree.h:4964:34: error: << on signed integer in
boolean context [-Werror]
#define LOOKUP_ONLYCONVERTING (1 << 2)
~~~^~~~~
../../gcc-trunk/gcc/cp/parser.c:11175:17: note: in expansion of macro
'LOOKUP_ONLYCONVERTING'
bool flags = LOOKUP_ONLYCONVERTING;
^~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[3]: *** [cp/parser.o] Error 1