diff options
author | Kaveh R. Ghazi <ghazi@caip.rutgers.edu> | 2005-07-19 12:09:49 +0000 |
---|---|---|
committer | Kaveh Ghazi <ghazi@gcc.gnu.org> | 2005-07-19 12:09:49 +0000 |
commit | 7876a41423b46245f7eec641217c8330ded8734a (patch) | |
tree | dca43bd0a0db3df3cbcc88768c895067aa836aba /gcc/testsuite/gcc.dg/format | |
parent | 98ea74375f446196ce2ff7a3d5f7f9587b3ced52 (diff) | |
download | gcc-7876a41423b46245f7eec641217c8330ded8734a.zip gcc-7876a41423b46245f7eec641217c8330ded8734a.tar.gz gcc-7876a41423b46245f7eec641217c8330ded8734a.tar.bz2 |
re PR c++/22476 (-Wmissing-format-attribute should pick out function pointer candidates also)
PR c/22476
* c-common.c (check_function_arguments): Call
'check_function_format' if either -Wformat or
-Wmissing-format-attribute are specified.
* c-format.c (check_function_format): Check -Wformat before
calling 'check_format_info'.
* c-opts.c (c_common_post_options): Don't warn for
-Wmissing-format-attribute without -Wformat.
* c-typeck.c (convert_for_assignment): Detect additional cases for
-Wmissing-format-attribute.
* doc/invoke.texi (-Wmissing-format-attribute): Document new
behavior.
testsuite:
* gcc.dg/format/miss-1.c, gcc.dg/format/miss-2.c: Don't
specify -Wformat for these tests.
* gcc.dg/format/miss-3.c, gcc.dg/format/miss-4.c,
gcc.dg/format/miss-5.c, gcc.dg/format/miss-6.c: New.
* gcc.dg/format/opt-6.c: Delete.
From-SVN: r102155
Diffstat (limited to 'gcc/testsuite/gcc.dg/format')
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-1.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-2.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-3.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-4.c | 32 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-5.c | 48 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/miss-6.c | 31 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/opt-6.c | 7 |
7 files changed, 139 insertions, 9 deletions
diff --git a/gcc/testsuite/gcc.dg/format/miss-1.c b/gcc/testsuite/gcc.dg/format/miss-1.c index 2345785..839f296 100644 --- a/gcc/testsuite/gcc.dg/format/miss-1.c +++ b/gcc/testsuite/gcc.dg/format/miss-1.c @@ -1,7 +1,7 @@ /* Test for warnings for missing format attributes. */ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wformat -Wmissing-format-attribute" } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ #include "format.h" diff --git a/gcc/testsuite/gcc.dg/format/miss-2.c b/gcc/testsuite/gcc.dg/format/miss-2.c index f3afe24..241b22d 100644 --- a/gcc/testsuite/gcc.dg/format/miss-2.c +++ b/gcc/testsuite/gcc.dg/format/miss-2.c @@ -2,7 +2,7 @@ relevant parameters for a format attribute; see c/1017. */ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -Wformat -Wmissing-format-attribute" } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ #include "format.h" diff --git a/gcc/testsuite/gcc.dg/format/miss-3.c b/gcc/testsuite/gcc.dg/format/miss-3.c new file mode 100644 index 0000000..c588bed --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/miss-3.c @@ -0,0 +1,26 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +void +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + noattr_t na1 = na; + noattr_t na2 = a; /* { dg-warning "candidate" "initialization warning" } */ + attr_t a1 = na; + attr_t a2 = a; + + vnoattr_t vna1 = vna; + vnoattr_t vna2 = va; /* { dg-warning "candidate" "initialization warning" } */ + vattr_t va1 = vna; + vattr_t va2 = va; +} diff --git a/gcc/testsuite/gcc.dg/format/miss-4.c b/gcc/testsuite/gcc.dg/format/miss-4.c new file mode 100644 index 0000000..9be5e4d --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/miss-4.c @@ -0,0 +1,32 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +void +foo1 (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + noattr_t na1, na2; + attr_t a1, a2; + + vnoattr_t vna1, vna2; + vattr_t va1, va2; + + na1 = na; + na2 = a; /* { dg-warning "candidate" "assignment warning" } */ + a1 = na; + a2 = a; + + vna1 = vna; + vna2 = va; /* { dg-warning "candidate" "assignment warning" } */ + va1 = vna; + va1 = va; +} diff --git a/gcc/testsuite/gcc.dg/format/miss-5.c b/gcc/testsuite/gcc.dg/format/miss-5.c new file mode 100644 index 0000000..eaf1473 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/miss-5.c @@ -0,0 +1,48 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +noattr_t +foo1 (noattr_t na, attr_t a, int i) +{ + if (i) + return na; + else + return a; /* { dg-warning "candidate" "return type warning" } */ +} + +attr_t +foo2 (noattr_t na, attr_t a, int i) +{ + if (i) + return na; + else + return a; +} + +vnoattr_t +foo3 (vnoattr_t vna, vattr_t va, int i) +{ + if (i) + return vna; + else + return va; /* { dg-warning "candidate" "return type warning" } */ +} + +vattr_t +foo4 (vnoattr_t vna, vattr_t va, int i) +{ + if (i) + return vna; + else + return va; +} diff --git a/gcc/testsuite/gcc.dg/format/miss-6.c b/gcc/testsuite/gcc.dg/format/miss-6.c new file mode 100644 index 0000000..abe221f --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/miss-6.c @@ -0,0 +1,31 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +typedef void (*noattr_t) (const char *, ...); +typedef noattr_t __attribute__ ((__format__(__printf__, 1, 2))) attr_t; + +typedef void (*vnoattr_t) (const char *, va_list); +typedef vnoattr_t __attribute__ ((__format__(__printf__, 1, 0))) vattr_t; + +extern void foo1 (noattr_t); +extern void foo2 (attr_t); +extern void foo3 (vnoattr_t); +extern void foo4 (vattr_t); + +void +foo (noattr_t na, attr_t a, vnoattr_t vna, vattr_t va) +{ + foo1 (na); + foo1 (a); /* { dg-warning "candidate" "parameter passing warning" } */ + foo2 (na); + foo2 (a); + + foo3 (vna); + foo3 (va); /* { dg-warning "candidate" "parameter passing warning" } */ + foo4 (vna); + foo4 (va); +} diff --git a/gcc/testsuite/gcc.dg/format/opt-6.c b/gcc/testsuite/gcc.dg/format/opt-6.c deleted file mode 100644 index 140da30..0000000 --- a/gcc/testsuite/gcc.dg/format/opt-6.c +++ /dev/null @@ -1,7 +0,0 @@ -/* Test diagnostics for options used on their own without - -Wformat. -Wmissing-format-attribute. */ -/* Origin: Joseph Myers <joseph@codesourcery.com> */ -/* { dg-do compile } */ -/* { dg-options "-Wmissing-format-attribute" } */ - -/* { dg-warning "warning: -Wmissing-format-attribute ignored without -Wformat" "ignored" { target *-*-* } 0 } */ |