C++ ObjC++ Var(warn_imported_macros) Warning
Warn about macros that have conflicting header units definitions.
+Wcompare-distinct-pointer-types
+C ObjC Var(warn_compare_distinct_pointer_types) Warning Init(1)
+Warn if pointers of distinct types are compared without a cast.
+
flang-info-include-translate
C++ Var(note_include_translate_yes)
Note #include directives translated to import declarations.
else
/* Avoid warning about the volatile ObjC EH puts on decls. */
if (!objc_ok)
- pedwarn (location, 0,
+ pedwarn (location, OPT_Wcompare_distinct_pointer_types,
"comparison of distinct pointer types lacks a cast");
if (result_type == NULL_TREE)
int qual = ENCODE_QUAL_ADDR_SPACE (as_common);
result_type = build_pointer_type
(build_qualified_type (void_type_node, qual));
- pedwarn (location, 0,
- "comparison of distinct pointer types lacks a cast");
+ pedwarn (location, OPT_Wcompare_distinct_pointer_types,
+ "comparison of distinct pointer types lacks a cast");
}
}
else if (code0 == POINTER_TYPE && null_pointer_constant_p (orig_op1))
-Wcast-align -Wcast-align=strict -Wcast-function-type -Wcast-qual
-Wchar-subscripts
-Wclobbered -Wcomment
+-Wcompare-distinct-pointer-types
-Wno-complain-wrong-lang
-Wconversion -Wno-coverage-mismatch -Wno-cpp
-Wdangling-else -Wdangling-pointer -Wdangling-pointer=@var{n}
@samp{f951: Warning: command-line option '-fno-rtti' is valid for C++/D/ObjC++ but not for Fortran},
which may be disabled with @option{-Wno-complain-wrong-lang}.
+@opindex Wcompare-distinct-pointer-types
+@item -Wcompare-distinct-pointer-types @r{(C and Objective-C only)}
+Warn if pointers of distinct types are compared without a cast. This
+warning is enabled by default.
+
@opindex Wconversion
@opindex Wno-conversion
@item -Wconversion
--- /dev/null
+/* { dg-do compile }
+ { dg-options "-O0" }
+ This testcase checks that warn_compare_distinct_pointer_types is enabled by
+ default. */
+
+typedef int __u32;
+
+struct xdp_md
+{
+ char *data;
+ char *data_meta;
+};
+
+int xdp_context (struct xdp_md *xdp)
+{
+ void *data = (void *)(long)xdp->data;
+ __u32 *metadata = (void *)(long)xdp->data_meta;
+ __u32 ret;
+
+ if (metadata + 1 > data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 1;
+ if (metadata + 1 >= data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 2;
+ if (metadata + 1 < data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 3;
+ if (metadata + 1 <= data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 4;
+ if (metadata + 1 == data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 5;
+ if (metadata + 1 != data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 5;
+
+ return 1;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wcompare-distinct-pointer-types" } */
+
+typedef int __u32;
+
+struct xdp_md
+{
+ char *data;
+ char *data_meta;
+};
+
+int xdp_context (struct xdp_md *xdp)
+{
+ void *data = (void *)(long)xdp->data;
+ __u32 *metadata = (void *)(long)xdp->data_meta;
+ __u32 ret;
+
+ if (metadata + 1 > data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 1;
+ if (metadata + 1 >= data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 2;
+ if (metadata + 1 < data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 3;
+ if (metadata + 1 <= data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 4;
+ if (metadata + 1 == data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 5;
+ if (metadata + 1 != data) /* { dg-warning "comparison of distinct pointer types" } */
+ return 5;
+
+ return 1;
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O0 -Wno-compare-distinct-pointer-types" } */
+
+typedef int __u32;
+
+struct xdp_md
+{
+ char *data;
+ char *data_meta;
+};
+
+int xdp_context (struct xdp_md *xdp)
+{
+ void *data = (void *)(long)xdp->data;
+ __u32 *metadata = (void *)(long)xdp->data_meta;
+ __u32 ret;
+
+ if (metadata + 1 > data) /* There shouldn't be a warning here. */
+ return 1;
+ if (metadata + 1 >= data) /* There shouldn't be a warning here. */
+ return 2;
+ if (metadata + 1 < data) /* There shouldn't be a warning here. */
+ return 3;
+ if (metadata + 1 <= data) /* There shouldn't be a warning here. */
+ return 4;
+ if (metadata + 1 == data) /* There shouldn't be a warning here. */
+ return 5;
+ if (metadata + 1 != data) /* There shouldn't be a warning here. */
+ return 5;
+
+ return 1;
+}