On Wed, Jan 19, 2011 at 10:53 PM, Florian Weimer <f...@deneb.enyo.de> wrote: > I get strange warnings when I do arithmetic involving TYPE_MAX_VALUE > (size_type_node), in particular this code: > > /* Multiplies MUL1 with MUL2, and adds ADD. Returns (size_t)-1 if the > result cannot be be represented as a size_t value. If ADD is > null_tree, treat it as a zero constant. > */ > tree > build_size_mult_saturated (tree mul1, tree mul2, tree add) > { > tree max_mul1, result; > max_mul1 = TYPE_MAX_VALUE (size_type_node); > if (add != NULL_TREE) > max_mul1 = size_binop(MINUS_EXPR, max_mul1, add); > max_mul1 = size_binop(TRUNC_DIV_EXPR, max_mul1, mul2); > result = size_binop (MULT_EXPR, mul1, mul2); > if (add != NULL_TREE) > result = size_binop (PLUS_EXPR, result, add); > return build3 (COND_EXPR, sizetype, > build2 (EQ_EXPR, sizetype, mul2, size_zero_node), > add == NULL_TREE ? size_zero_node : add, > build3 (COND_EXPR, sizetype, > build2 (LE_EXPR, sizetype, mul1, max_mul1), > result, TYPE_MAX_VALUE (size_type_node))); > } > > Is size_type_node really signed, and does TYPE_MAX_VALUE > (size_type_node) lie outside the representable range? Is there an > easy way to get a GCC type closely matching size_t in C++?
The size_* functions are supposed to be used with sizetype, not with size_type ;) sizetypes are strange beast. Richard.