+2014-04-11 Tobias Burnus <burnus@net-b.de>
+
+ PR c/60194
+ * doc/invoke.texi (-Wformat-signedness): Document it.
+ (Wformat=2): Mention that this enables -Wformat-signedness.
+
2014-04-11 Joern Rennecke <joern.rennecke@embecosm.com>
* common/config/epiphany/epiphany-common.c
+2014-04-11 Tobias Burnus <burnus@net-b.de>
+
+ PR c/60194
+ * c.opt (Wformat-signedness): Add
+ * c-format.c(check_format_types): Use it.
+
2014-04-11 Jason Merrill <jason@redhat.com>
PR c++/57926
a second level of indirection. */
if (TREE_CODE (wanted_type) == INTEGER_TYPE
&& TREE_CODE (cur_type) == INTEGER_TYPE
- && (!pedantic || i == 0 || (i == 1 && char_type_flag))
+ && ((!pedantic && !warn_format_signedness)
+ || (i == 0 && !warn_format_signedness)
+ || (i == 1 && char_type_flag))
&& (TYPE_UNSIGNED (wanted_type)
? wanted_type == c_common_unsigned_type (cur_type)
: wanted_type == c_common_signed_type (cur_type)))
C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
Warn about possible security problems with format functions
+Wformat-signedness
+C ObjC C++ ObjC++ Var(warn_format_signedness) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0)
+Warn about sign differences with format functions
+
Wformat-y2k
C ObjC C++ ObjC++ Var(warn_format_y2k) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=,warn_format >= 2, 0)
Warn about strftime formats yielding 2-digit years
-Wno-endif-labels -Werror -Werror=* @gol
-Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
-Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
--Wformat-security -Wformat-y2k @gol
+-Wformat-security -Wformat-signedness -Wformat-y2k @gol
-Wframe-larger-than=@var{len} -Wno-free-nonheap-object -Wjump-misses-init @gol
-Wignored-qualifiers @gol
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int @gol
@opindex Wformat=2
Enable @option{-Wformat} plus additional format checks. Currently
equivalent to @option{-Wformat -Wformat-nonliteral -Wformat-security
--Wformat-y2k}.
+-Wformat-signedness -Wformat-y2k}.
@item -Wformat-nonliteral
@opindex Wformat-nonliteral
in future warnings may be added to @option{-Wformat-security} that are not
included in @option{-Wformat-nonliteral}.)
+@item -Wformat-signedness
+@opindex Wformat-signedness
+@opindex Wno-format-signedness
+If @option{-Wformat} is specified, also warn if the format string
+requires an unsigned argument and the argument is signed and vice versa.
+
@item -Wformat-y2k
@opindex Wformat-y2k
@opindex Wno-format-y2k
+2014-04-11 Tobias Burnus <burnus@net-b.de>
+
+ PR c/60194
+ * * g++.dg/warn/warn_format_signedness.C: New.
+ * gcc.dg/format/warn-signedness.c: New.
+
2014-04-11 Tobias Burnus <burnus@net-b.de>
PR fortran/58880
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wformat -Wformat-signedness" } */
+
+/* PR c/60194 */
+
+void foo(unsigned u, int i, unsigned char uc, signed char sc) {
+ __builtin_printf("%d\n", u); /* { dg-warning "expects argument of type 'int', but argument 2 has type 'unsigned int'" } */
+ __builtin_printf("%u\n", i); /* { dg-warning "expects argument of type 'unsigned int', but argument 2 has type 'int'" } */
+ __builtin_printf("%c\n", sc);
+ __builtin_printf("%c\n", uc);
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wformat -Wformat-signedness" } */
+
+/* PR c/60194 */
+
+void foo(unsigned u, int i, unsigned char uc, signed char sc) {
+ __builtin_printf("%d\n", u); /* { dg-warning "expects argument of type 'int', but argument 2 has type 'unsigned int'" } */
+ __builtin_printf("%u\n", i); /* { dg-warning "expects argument of type 'unsigned int', but argument 2 has type 'int'" } */
+ __builtin_printf("%c\n", sc);
+ __builtin_printf("%c\n", uc);
+}