Message ID | AM4PR0701MB2162D459F858784668E47F78E4CE0@AM4PR0701MB2162.eurprd07.prod.outlook.com |
---|---|
State | New |
Headers | show |
On Thu, Sep 29, 2016 at 3:58 PM, Bernd Edlinger <bernd.edlinger@hotmail.de> wrote: > Unfortunately, without that exception there is a false positive: > > In file included from ../../gcc-trunk/gcc/ada/gcc-interface/decl.c:30:0: > ../../gcc-trunk/gcc/ada/gcc-interface/decl.c: In function 'int > adjust_packed(tree, tree, int)': > ../../gcc-trunk/gcc/tree.h:1874:22: error: << on signed integer in > boolean context [-Werror=int-in-bool-context] > ? ((unsigned)1) << ((NODE)->type_common.align - 1) : 0) > ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ah, this issue again: the shift isn't in boolean context, it's in integer context. I think we want to be a lot more conservative about these warnings in the arms of a COND_EXPR. In fact, I think the entire /* Distribute the conversion into the arms of a COND_EXPR. */ section is wrong now that we're doing delayed folding. Jason
Index: c-common.c =================================================================== --- c-common.c (revision 240571) +++ c-common.c (working copy) @@ -4655,6 +4655,14 @@ c_common_truthvalue_conversion (location_t locatio return c_common_truthvalue_conversion (location, TREE_OPERAND (expr, 0)); + case LSHIFT_EXPR: + /* Warn on signed integer left shift. */ + if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE + && !TYPE_UNSIGNED (TREE_TYPE (expr))) + warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, + "<< on signed integer in boolean context"); + break; + case COND_EXPR: if (warn_int_in_bool_context && !from_macro_definition_at (EXPR_LOCATION (expr)))