c-family: 2016-10-17 Bernd Edlinger * c-common.c (c_common_truthvalue_conversion): Warn only for signed integer shift ops in boolean context. testsuite: 2016-10-17 Bernd Edlinger * c-c++-common/Wint-in-bool-context-2.c: New test. Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 241270) +++ gcc/c-family/c-common.c (working copy) @@ -3328,8 +3328,10 @@ TREE_OPERAND (expr, 0)); case LSHIFT_EXPR: - warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, - "<< in boolean context, did you mean '<' ?"); + if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE + && !TYPE_UNSIGNED (TREE_TYPE (expr))) + warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, + "<< in boolean context, did you mean '<' ?"); break; case COND_EXPR: Index: gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c =================================================================== --- gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (revision 0) +++ gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (working copy) @@ -0,0 +1,17 @@ +/* { dg-options "-Wint-in-bool-context" } */ +/* { dg-do compile } */ + +typedef unsigned u32; +typedef unsigned char u8; +#define KEYLENGTH 8 + +int foo (u8 plen, u32 key) +{ + if ((plen < KEYLENGTH) && (key << plen)) /* { dg-bogus "boolean context" } */ + return -1; + + if ((plen << KEYLENGTH) && (key < plen)) /* { dg-warning "boolean context" } */ + return -2; + + return 0; +}