@@ -2760,6 +2760,13 @@ static int cast_flags(struct expression *expr, struct expression *old)
*/
else if (old->flags & CEF_FLOAT)
flags = CEF_SET_ICE;
+ } else if (class & TYPE_PTR) {
+ /*
+ * Casts of integer literals to pointer type yield
+ * address constants [6.6(9)].
+ */
+ if (old->flags & CEF_INT)
+ flags = CEF_ADDR;
}
return flags;
new file mode 100644
@@ -0,0 +1,13 @@
+static int *a = (int*)0; // OK
+static int b = 0;
+static int *c = (int*)b; // KO
+
+
+/*
+ * check-name: integer literal cast to pointer type constness verification.
+ * check-command: sparse -Wconstexpr-not-const $file
+ *
+ * check-error-start
+constexpr-pointer-cast.c:3:18: warning: non-constant initializer for static object
+ * check-error-end
+ */