OSDN Git Service

* typeck.c (build_binary_op): Issue warning if either operand of a
[pf3gnuchains/gcc-fork.git] / gcc / cp / typeck.c
index 60ef195..0cae938 100644 (file)
@@ -3089,6 +3089,10 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
     case NE_EXPR:
       if (warn_float_equal && (code0 == REAL_TYPE || code1 == REAL_TYPE))
        warning (0, "comparing floating point with == or != is unsafe");
+      if ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1))
+         || (TREE_CODE (orig_op1) == STRING_CST && !integer_zerop (op0)))
+       warning (OPT_Wstring_literal_comparison,
+                "comparison with string literal");
 
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
@@ -3194,6 +3198,11 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
     case GE_EXPR:
     case LT_EXPR:
     case GT_EXPR:
+      if (TREE_CODE (orig_op0) == STRING_CST
+         || TREE_CODE (orig_op1) == STRING_CST)
+       warning (OPT_Wstring_literal_comparison,
+                "comparison with string literal");
+
       build_type = boolean_type_node;
       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
           && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
@@ -3688,7 +3697,7 @@ build_x_unary_op (enum tree_code code, tree xarg)
            }
          else
            {
-             error ("parenthesis around %qE cannot be used to form a"
+             error ("parentheses around %qE cannot be used to form a"
                     " pointer-to-member-function",
                     xarg);
              PTRMEM_OK_P (xarg) = 1;