aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorJoseph Myers <jsm@polyomino.org.uk>2004-07-01 09:52:33 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2004-07-01 09:52:33 +0100
commitede1a3872913df59f3a1f4299ec5f6c7706d3b7b (patch)
tree5e14fad8701c2b2a0d71a2e08df216891b59d315 /gcc/testsuite
parentd59c7b4bdca296330783083e285ec0fab406df28 (diff)
downloadgcc-ede1a3872913df59f3a1f4299ec5f6c7706d3b7b.zip
gcc-ede1a3872913df59f3a1f4299ec5f6c7706d3b7b.tar.gz
gcc-ede1a3872913df59f3a1f4299ec5f6c7706d3b7b.tar.bz2
re PR c/1027 (slightly misleading printf format warning)
PR c/1027 * c-lang.c (c_initialize_diagnostics): Move from here ... * c-objc-common.c: ... to here. Include "c-pretty-print.h". (c_tree_printer): Use pretty-printer to format %T. * c-pretty-print.c (pp_c_specifier_qualifier_list): Include space before '*' if not C++. (pp_c_direct_abstract_declarator): Don't try to print array upper bound for flexible array members. * c-tree.h: Include "diagnostic.h". (c_initialize_diagnostics): Declare. * objc/objc-lang.c (LANG_HOOKS_INITIALIZE_DIAGNOSTICS): Define. * c-format.c (format_type_warning): New function. Improve diagnostics for incorrect format argument types. (check_format_types): Use it. Add two parameters. Use the TYPE_MAIN_VARIANT of wanted_type. (check_format_info_main): Pass new parameters to check_format_types. (struct format_wanted_type): Update comment. testsuite: * gcc.dg/Wswitch-enum.c, gcc.dg/Wswitch.c, gcc.dg/format/branch-1.c, gcc.dg/format/diag-1.c, gcc.dg/format/multattr-3.c, gcc.dg/format/xopen-1.c: Update expected warning text. * gcc.dg/format/diag-2.c: New test. From-SVN: r83965
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog9
-rw-r--r--gcc/testsuite/gcc.dg/Wswitch-enum.c4
-rw-r--r--gcc/testsuite/gcc.dg/Wswitch.c2
-rw-r--r--gcc/testsuite/gcc.dg/format/branch-1.c12
-rw-r--r--gcc/testsuite/gcc.dg/format/diag-1.c6
-rw-r--r--gcc/testsuite/gcc.dg/format/diag-2.c13
-rw-r--r--gcc/testsuite/gcc.dg/format/multattr-3.c12
-rw-r--r--gcc/testsuite/gcc.dg/format/xopen-1.c2
8 files changed, 41 insertions, 19 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0fa26ef..5ce65da 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,12 @@
+2004-07-01 Joseph S. Myers <jsm@polyomino.org.uk>
+
+ PR c/1027
+ * gcc.dg/Wswitch-enum.c, gcc.dg/Wswitch.c,
+ gcc.dg/format/branch-1.c, gcc.dg/format/diag-1.c,
+ gcc.dg/format/multattr-3.c, gcc.dg/format/xopen-1.c: Update
+ expected warning text.
+ * gcc.dg/format/diag-2.c: New test.
+
2004-07-01 Eric Botcazou <ebotcazou@libertysurf.fr>
* gcc.c-torture/compile/20040323-1.c: XFAIL on Solaris 2.
diff --git a/gcc/testsuite/gcc.dg/Wswitch-enum.c b/gcc/testsuite/gcc.dg/Wswitch-enum.c
index b51ecfd..24fc262 100644
--- a/gcc/testsuite/gcc.dg/Wswitch-enum.c
+++ b/gcc/testsuite/gcc.dg/Wswitch-enum.c
@@ -50,13 +50,13 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
{
case e1: return 1;
case e2: return 2;
- case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `e'" "excess 3" } */
+ case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `enum e'" "excess 3" } */
}
switch (ep)
{
case e1: return 1;
case e2: return 2;
- case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `e'" "excess 3" } */
+ case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `enum e'" "excess 3" } */
default: break;
}
return 0;
diff --git a/gcc/testsuite/gcc.dg/Wswitch.c b/gcc/testsuite/gcc.dg/Wswitch.c
index e3deeab..9ba12d6 100644
--- a/gcc/testsuite/gcc.dg/Wswitch.c
+++ b/gcc/testsuite/gcc.dg/Wswitch.c
@@ -50,7 +50,7 @@ foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
{
case e1: return 1;
case e2: return 2;
- case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `e'" "excess 3" } */
+ case 3: return 3; /* { dg-warning "case value `3' not in enumerated type `enum e'" "excess 3" } */
}
switch (ep)
{
diff --git a/gcc/testsuite/gcc.dg/format/branch-1.c b/gcc/testsuite/gcc.dg/format/branch-1.c
index 2d07104..cdff927 100644
--- a/gcc/testsuite/gcc.dg/format/branch-1.c
+++ b/gcc/testsuite/gcc.dg/format/branch-1.c
@@ -9,18 +9,18 @@ void
foo (long l, int nfoo)
{
printf ((nfoo > 1) ? "%d foos" : "%d foo", nfoo);
- printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
- printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
- printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int format" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%d foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%ld foos" : "%d foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf ((l > 1) ? "%d foos" : "%ld foo", l); /* { dg-warning "int" "wrong type in conditional expr" } */
/* Should allow one case to have extra arguments. */
printf ((nfoo > 1) ? "%d foos" : "1 foo", nfoo);
printf ((nfoo > 1) ? "many foos" : "1 foo", nfoo); /* { dg-warning "too many" "too many args in all branches" } */
printf ((nfoo > 1) ? "%d foos" : "", nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "1 foo" : "no foos"), nfoo);
printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo);
- printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
- printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
- printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int format" "wrong type" } */
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%d foo" : "%ld foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf ((nfoo > 1) ? "%ld foos" : ((nfoo > 0) ? "%d foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf ((nfoo > 1) ? "%d foos" : ((nfoo > 0) ? "%ld foo" : "%d foos"), nfoo); /* { dg-warning "long int" "wrong type" } */
/* Extra arguments to NULL should be complained about. */
printf (NULL, "foo"); /* { dg-warning "too many" "NULL extra args" } */
/* { dg-warning "null" "null format arg" { target *-*-* } 25 } */
diff --git a/gcc/testsuite/gcc.dg/format/diag-1.c b/gcc/testsuite/gcc.dg/format/diag-1.c
index 1c9a246..998e35b 100644
--- a/gcc/testsuite/gcc.dg/format/diag-1.c
+++ b/gcc/testsuite/gcc.dg/format/diag-1.c
@@ -12,7 +12,7 @@ foo (double d)
printf ("%hhf", d); /* { dg-warning "hh" "%hhf warning" } */
/* This should get a message referring to `ll', not to `q'. */
printf ("%llf", d); /* { dg-warning "ll" "%llf warning" } */
- /* This should get a message referring to `size_t format', not to
- `unsigned int format' or similar. */
- printf ("%zu", d); /* { dg-warning "size_t format" "size_t format warning" } */
+ /* This should get a message referring to 'size_t', not to
+ 'unsigned int' or similar. */
+ printf ("%zu", d); /* { dg-warning "size_t" "size_t format warning" } */
}
diff --git a/gcc/testsuite/gcc.dg/format/diag-2.c b/gcc/testsuite/gcc.dg/format/diag-2.c
new file mode 100644
index 0000000..e7578d3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/diag-2.c
@@ -0,0 +1,13 @@
+/* Test for format diagnostics. Proper type names (bug 1027). */
+/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#include "format.h"
+
+void
+foo (double d)
+{
+ printf ("%s", &d); /* { dg-warning "char \\*" "correct arg type" } */
+ scanf ("%zu", &d); /* { dg-warning "size_t \\*" "correct arg type" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/multattr-3.c b/gcc/testsuite/gcc.dg/format/multattr-3.c
index 40467fe..1d4979a 100644
--- a/gcc/testsuite/gcc.dg/format/multattr-3.c
+++ b/gcc/testsuite/gcc.dg/format/multattr-3.c
@@ -13,16 +13,16 @@ void
foo (long l, int nfoo)
{
printf (ngettext ("%d foo", "%d foos", nfoo), nfoo);
- printf (ngettext ("%d foo", "%d foos", l), l); /* { dg-warning "int format" "wrong type in conditional expr" } */
- printf (ngettext ("%d foo", "%ld foos", l), l); /* { dg-warning "int format" "wrong type in conditional expr" } */
- printf (ngettext ("%ld foo", "%d foos", l), l); /* { dg-warning "int format" "wrong type in conditional expr" } */
+ printf (ngettext ("%d foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf (ngettext ("%d foo", "%ld foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
+ printf (ngettext ("%ld foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */
/* Should allow one case to have extra arguments. */
printf (ngettext ("1 foo", "%d foos", nfoo), nfoo);
printf (ngettext ("1 foo", "many foos", nfoo), nfoo); /* { dg-warning "too many" "too many args in all branches" } */
printf (ngettext ("", "%d foos", nfoo), nfoo);
printf (ngettext ("1 foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo);
- printf (ngettext ("%ld foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int format" "wrong type" } */
- printf (ngettext ("%d foo", (nfoo > 0) ? "%ld foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int format" "wrong type" } */
- printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "%ld foos", nfoo), nfoo); /* { dg-warning "long int format" "wrong type" } */
+ printf (ngettext ("%ld foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf (ngettext ("%d foo", (nfoo > 0) ? "%ld foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
+ printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "%ld foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */
}
diff --git a/gcc/testsuite/gcc.dg/format/xopen-1.c b/gcc/testsuite/gcc.dg/format/xopen-1.c
index 1462a2c..9b098fb 100644
--- a/gcc/testsuite/gcc.dg/format/xopen-1.c
+++ b/gcc/testsuite/gcc.dg/format/xopen-1.c
@@ -89,7 +89,7 @@ foo (int i, unsigned int u, wint_t lc, wchar_t *ls, int *ip, double d,
/* The use of operand number $ formats is an X/Open extension. */
scanf ("%1$d", ip);
printf ("%1$d", i);
- printf ("%1$d", l); /* { dg-warning "arg 2" "mismatched args with $ format" } */
+ printf ("%1$d", l); /* { dg-warning "arg 2|argument 2" "mismatched args with $ format" } */
printf ("%3$*2$.*1$ld", i2, i, l);
printf ("%4$ld%7$ld%5$d%6$d%3$d%1$d%2$d", i, i, i, l, i, i, l);
scanf ("%4$ld%7$ld%5$d%6$d%3$d%1$d%2$d", ip, ip, ip, lp, ip, ip, lp);