commit 3d382500ccb766eb1c6dea69a32348d62c86b950 Author: Jason Merrill Date: Wed Nov 18 16:30:06 2015 -0500 * c-common.c (shorten_compare): Don't -Wtype-limits if the non-constant operand comes from a macro. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f50ca48..068a0bc 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4650,7 +4650,9 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr, type = c_common_unsigned_type (type); } - if (TREE_CODE (primop0) != INTEGER_CST) + if (TREE_CODE (primop0) != INTEGER_CST + /* Don't warn if it's from a macro. */ + && !from_macro_expansion_at (EXPR_LOCATION (primop0))) { if (val == truthvalue_false_node) warning_at (loc, OPT_Wtype_limits, diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits2.C b/gcc/testsuite/g++.dg/warn/Wtype-limits2.C new file mode 100644 index 0000000..a46baad --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wtype-limits2.C @@ -0,0 +1,11 @@ +// { dg-options -Wtype-limits } + +unsigned char array[4]; +bool b; +#define VAL (b ? array[0] : (unsigned char)0) + +int main() +{ + if (VAL > 1000) + __builtin_abort(); +}