------- Comment #3 from pinskia at gcc dot gnu dot org 2008-03-29 19:44 ------- This is the patch which I am testing: Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 133711) +++ cp/typeck.c (working copy) @@ -3917,6 +3917,10 @@ cp_build_binary_op (enum tree_code code, int unsignedp0, unsignedp1; tree primop0 = get_narrower (op0, &unsignedp0); tree primop1 = get_narrower (op1, &unsignedp1); + tree undertype = result_type; + + if (TREE_CODE (undertype) == COMPLEX_TYPE) + undertype = TREE_TYPE (undertype);
/* Check for comparison of different enum types. */ if (TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE @@ -3937,7 +3941,7 @@ cp_build_binary_op (enum tree_code code, /* Do not warn if the comparison is being done in a signed type, since the signed type will only be chosen if it can represent all the values of the unsigned type. */ - if (!TYPE_UNSIGNED (result_type)) + if (!TYPE_UNSIGNED (undertype)) /* OK */; /* Do not warn if both operands are unsigned. */ else if (op0_signed == op1_signed) @@ -3955,10 +3959,10 @@ cp_build_binary_op (enum tree_code code, else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR) && ((op0_signed && TREE_CODE (orig_op1) == INTEGER_CST && int_fits_type_p (orig_op1, c_common_signed_type - (result_type))) + (undertype))) || (op1_signed && TREE_CODE (orig_op0) == INTEGER_CST && int_fits_type_p (orig_op0, c_common_signed_type - (result_type))))) + (undertype))))) /* OK */; else if (complain & tf_warning) warning (OPT_Wsign_compare, Index: c-typeck.c =================================================================== --- c-typeck.c (revision 133711) +++ c-typeck.c (working copy) @@ -8483,6 +8483,9 @@ build_binary_op (enum tree_code code, tr { tree sop, uop; bool ovf; + tree undertype = result_type; + if (TREE_CODE (undertype) == COMPLEX_TYPE) + undertype = TREE_TYPE (undertype); if (op0_signed) sop = xop0, uop = xop1; @@ -8502,7 +8505,7 @@ build_binary_op (enum tree_code code, tr else if (TREE_CODE (uop) == INTEGER_CST && (resultcode == EQ_EXPR || resultcode == NE_EXPR) && int_fits_type_p - (uop, c_common_signed_type (result_type))) + (uop, c_common_signed_type (undertype))) /* OK */; /* Do not warn if the unsigned quantity is an enumeration constant and its maximum value would fit in the result @@ -8511,7 +8514,7 @@ build_binary_op (enum tree_code code, tr && TREE_CODE (TREE_TYPE (uop)) == ENUMERAL_TYPE && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (uop)), - c_common_signed_type (result_type))) + c_common_signed_type (undertype))) /* OK */; else warning (OPT_Wsign_compare, "comparison between signed and unsigned"); -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35430