@@ -3597,8 +3597,10 @@ parser_build_binary_op (location_t locat
of testing for equality or inequality of a string literal with NULL. */
if (code == EQ_EXPR || code == NE_EXPR)
{
- if ((code1 == STRING_CST && !integer_zerop (arg2.value))
- || (code2 == STRING_CST && !integer_zerop (arg1.value)))
+ if ((code1 == STRING_CST
+ && !integer_zerop (tree_strip_nop_conversions (arg2.value)))
+ || (code2 == STRING_CST
+ && !integer_zerop (tree_strip_nop_conversions (arg1.value))))
warning_at (location, OPT_Waddress,
"comparison with string literal results in unspecified behavior");
}
@@ -4487,9 +4487,12 @@ cp_build_binary_op (location_t location,
warning (OPT_Wfloat_equal,
"comparing floating point with == or != is unsafe");
if ((complain & tf_warning)
- && ((TREE_CODE (orig_op0) == STRING_CST && !integer_zerop (op1))
- || (TREE_CODE (orig_op1) == STRING_CST && !integer_zerop (op0))))
- warning (OPT_Waddress, "comparison with string literal results in unspecified behaviour");
+ && ((TREE_CODE (orig_op0) == STRING_CST
+ && !integer_zerop (tree_strip_nop_conversions (op1)))
+ || (TREE_CODE (orig_op1) == STRING_CST
+ && !integer_zerop (tree_strip_nop_conversions (op0)))))
+ warning (OPT_Waddress, "comparison with string literal results "
+ "in unspecified behaviour");
build_type = boolean_type_node;
if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
@@ -0,0 +1,15 @@
+/* PR c/69768 */
+/* { dg-do compile } */
+/* { dg-options "-Waddress" } */
+
+static int e;
+
+int
+foo ()
+{
+ return "foo1" != (void *) 0 /* { dg-bogus "comparison with string literal results in unspecified behaviou?r" } */
+ && "foo2" != (const char *) ((void *) 0) /* { dg-bogus "comparison with string literal results in unspecified behaviou?r" } */
+ && "foo3" != (const char *) ((void *) (10 - 10)) /* { dg-warning "comparison with string literal results in unspecified behaviou?r" "" { target c++11 } } */
+ && "foo4" != (const char *) ((void *) (&e - &e)) /* { dg-warning "comparison with string literal results in unspecified behaviou?r" "" { target { c || c++11 } } } */
+ && "foo5" != "foo6"; /* { dg-warning "comparison with string literal results in unspecified behaviou?r" } */
+}