OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /openrisc/trunk/gnu-src/gcc-4.2.2/gcc/testsuite/gcc.dg/format
    from Rev 149 to Rev 154
    Reverse comparison

Rev 149 → Rev 154

/nonlit-1.c
0,0 → 1,13
/* Test for warnings for non-string-literal formats. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */
 
#include "format.h"
 
void
foo (char *s, size_t i)
{
printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */
printf (s, i); /* { dg-warning "argument types" "non-literal" } */
}
nonlit-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: bitfld-1.c =================================================================== --- bitfld-1.c (nonexistent) +++ bitfld-1.c (revision 154) @@ -0,0 +1,51 @@ +/* Test for printf formats and bit-fields: bug 22421. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ +/* { dg-require-effective-target int32plus } */ + +#include "format.h" + +struct s { + unsigned int u1 : 1; + signed int s1 : 1; + unsigned int u15 : 15; + signed int s15 : 15; + unsigned int u16 : 16; + signed int s16 : 16; + unsigned long u31 : 31; + signed long s31 : 31; + unsigned long u32 : 32; + signed long s32 : 32; + unsigned long long u48 : 48; +} x; + +void +foo (void) +{ + printf ("%d%u", x.u1, x.u1); + printf ("%d%u", x.s1, x.s1); + printf ("%d%u", x.u15, x.u15); + printf ("%d%u", x.s15, x.s15); + printf ("%d%u", x.u16, x.u16); + printf ("%d%u", x.s16, x.s16); +#if __INT_MAX__ > 32767 + /* If integers are 16 bits, there doesn't seem to be a way of + printing these without getting an error. */ + printf ("%d%u", x.u31, x.u31); + printf ("%d%u", x.s31, x.s31); +#endif +#if __LONG_MAX__ > 2147483647 && __INT_MAX__ >= 2147483647 + /* If long is wider than 32 bits, the 32-bit bit-fields are int or + unsigned int or promote to those types. Otherwise, long is 32 + bits and the bit-fields are of type plain long or unsigned + long. */ + printf ("%d%u", x.u32, x.u32); + printf ("%d%u", x.s32, x.s32); +#else + printf ("%ld%lu", x.u32, x.u32); + printf ("%ld%lu", x.s32, x.s32); +#endif + printf ("%llu", x.u48); /* { dg-warning "has type '.*unsigned int:48'" } */ + printf ("%llu", (unsigned long long)x.u48); +}
bitfld-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-printf-2.c =================================================================== --- c99-printf-2.c (nonexistent) +++ c99-printf-2.c (revision 154) @@ -0,0 +1,32 @@ +/* Test for printf formats. Formats using extensions to the standard + should be rejected in strict pedantic mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, long long ll, size_t z, wint_t lc, wchar_t *ls) +{ + /* The length modifiers q, Z and L as applied to integer formats are + extensions. + */ + printf ("%qd", ll); /* { dg-warning "C" "%q length" } */ + printf ("%Ld", ll); /* { dg-warning "C" "%L length" } */ + printf ("%Zd", z); /* { dg-warning "C" "%Z length" } */ + /* The conversion specifiers C and S are X/Open extensions; the + conversion specifier m is a GNU extension. + */ + printf ("%m"); /* { dg-warning "C" "printf %m" } */ + printf ("%C", lc); /* { dg-warning "C" "printf %C" } */ + printf ("%S", ls); /* { dg-warning "C" "printf %S" } */ + /* The flag character ', and the use of operand number $ formats, are + X/Open extensions. + */ + printf ("%'d", i); /* { dg-warning "C" "printf ' flag" } */ + printf ("%1$d", i); /* { dg-warning "C" "printf $ format" } */ + /* The flag character I is a GNU extension. */ + printf ("%Id", i); /* { dg-warning "C" "printf I flag" } */ +}
c99-printf-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: nonlit-3.c =================================================================== --- nonlit-3.c (nonexistent) +++ nonlit-3.c (revision 154) @@ -0,0 +1,12 @@ +/* Test for warnings for non-string-literal formats. Test for strftime formats. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wformat-nonliteral" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp, char *fmt) +{ + strftime (s, m, fmt, tp); /* { dg-warning "format string" "non-literal" } */ +}
nonlit-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: diag-2.c =================================================================== --- diag-2.c (nonexistent) +++ diag-2.c (revision 154) @@ -0,0 +1,13 @@ +/* Test for format diagnostics. Proper type names (bug 1027). */ +/* Origin: Joseph Myers */ +/* { 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" } */ +}
diag-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: builtin-1.c =================================================================== --- builtin-1.c (nonexistent) +++ builtin-1.c (revision 154) @@ -0,0 +1,22 @@ +/* Test for format extensions. Test that the __builtin functions get their + default attributes even with -ffreestanding. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -ffreestanding" } */ + +#include "format.h" + +void +foo (int i) +{ + __builtin_fprintf (stdout, "%d", i); + __builtin_fprintf (stdout, "%ld", i); /* { dg-warning "format" "__builtin_fprintf" } */ + __builtin_printf ("%d", i); + __builtin_printf ("%ld", i); /* { dg-warning "format" "__builtin_printf" } */ + + __builtin_fprintf_unlocked (stdout, "%d", i); + __builtin_fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "__builtin_fprintf_unlocked" } */ + __builtin_printf_unlocked ("%d", i); + __builtin_printf_unlocked ("%ld", i); /* { dg-warning "format" "__builtin_printf_unlocked" } */ +}
builtin-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: asm_fprintf-1.c =================================================================== --- asm_fprintf-1.c (nonexistent) +++ asm_fprintf-1.c (revision 154) @@ -0,0 +1,80 @@ +/* Test for asm_fprintf formats. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +/* Magic identifier must be set before the attribute is used. */ +typedef long long __gcc_host_wide_int__; + +extern int asm_fprintf (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))) __attribute__ ((__nonnull__)); + +void +foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, + int *n, short int *hn, long int l, unsigned long int ul, + long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll, + ullong ull, unsigned int *un, const int *cn, signed char *ss, + unsigned char *us, const signed char *css, unsigned int u1, + unsigned int u2) +{ + /* Acceptable C90 specifiers, flags and modifiers. */ + asm_fprintf ("%%"); + asm_fprintf ("%d%i%o%u%x%X%c%s%%", i, i, u, u, u, u, i, s); + asm_fprintf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul); + asm_fprintf ("%lld%lli%llo%llu%llx%llX", ll, ll, ull, ull, ull, ull); + asm_fprintf ("%-d%-i%-o%-u%-x%-X%-c%-s", i, i, u, u, u, u, i, s); + asm_fprintf ("% d% i\n", i, i); + asm_fprintf ("%#o%#x%#X", u, u, u); + asm_fprintf ("%08d%08i%08o%08u%08x%08X", i, i, u, u, u, u); + asm_fprintf ("%d\n", i); + asm_fprintf ("%+d\n", i); + asm_fprintf ("%3d\n", i); + asm_fprintf ("%-3d\n", i); + asm_fprintf ("%.7d\n", i); + asm_fprintf ("%+9.4d\n", i); + asm_fprintf ("%.3ld\n", l); + asm_fprintf ("%d %lu\n", i, ul); + + /* Extensions provided in asm_fprintf. */ + asm_fprintf ("%O%R%I%L%U%@"); + asm_fprintf ("%r", i); + asm_fprintf ("%wd%wi%wo%wu%wx%wX", ll, ll, ull, ull, ull, ull); + + /* Standard specifiers not accepted in asm_fprintf. */ + asm_fprintf ("%f\n", d); /* { dg-warning "format" "float" } */ + asm_fprintf ("%e\n", d); /* { dg-warning "format" "float" } */ + asm_fprintf ("%E\n", d); /* { dg-warning "format" "float" } */ + asm_fprintf ("%g\n", d); /* { dg-warning "format" "float" } */ + asm_fprintf ("%G\n", d); /* { dg-warning "format" "float" } */ + asm_fprintf ("%p\n", p); /* { dg-warning "format" "pointer" } */ + asm_fprintf ("%n\n", n); /* { dg-warning "format" "counter" } */ + asm_fprintf ("%hd\n", i); /* { dg-warning "format" "conversion" } */ + + /* Various tests of bad argument types. */ + asm_fprintf ("%d", l); /* { dg-warning "format" "bad argument types" } */ + asm_fprintf ("%wd", l); /* { dg-warning "format" "bad argument types" } */ + asm_fprintf ("%d", ll); /* { dg-warning "format" "bad argument types" } */ + asm_fprintf ("%*d\n", i1, i); /* { dg-warning "format" "bad * argument types" } */ + asm_fprintf ("%.*d\n", i2, i); /* { dg-warning "format" "bad * argument types" } */ + asm_fprintf ("%*.*ld\n", i1, i2, l); /* { dg-warning "format" "bad * argument types" } */ + asm_fprintf ("%ld", i); /* { dg-warning "format" "bad argument types" } */ + asm_fprintf ("%s", n); /* { dg-warning "format" "bad argument types" } */ + + /* Wrong number of arguments. */ + asm_fprintf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */ + asm_fprintf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */ + /* Miscellaneous bogus constructions. */ + asm_fprintf (""); /* { dg-warning "zero-length" "warning for empty format" } */ + asm_fprintf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ + asm_fprintf ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */ + asm_fprintf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ + asm_fprintf (NULL); /* { dg-warning "null" "null format string warning" } */ + asm_fprintf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ + asm_fprintf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */ + asm_fprintf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ + asm_fprintf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ + + /* Make sure we still get warnings for regular printf. */ + printf ("%d\n", ll); /* { dg-warning "format" "bad argument types" } */ +}
asm_fprintf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: null-1.c =================================================================== --- null-1.c (nonexistent) +++ null-1.c (revision 154) @@ -0,0 +1,27 @@ +/* Test for some aspects of null format string handling. */ +/* Origin: Jason Thorpe */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +extern void my_printf (const char *, ...) __attribute__((format(printf,1,2))); +extern const char *my_format (const char *, const char *) + __attribute__((format_arg(2))); + +void +foo (int i1) +{ + /* Warning about a null format string has been decoupled from the actual + format check. However, we still expect to be warned about any excess + arguments after a null format string. */ + my_printf (NULL); + my_printf (NULL, i1); /* { dg-warning "too many" "null format with arguments" } */ + + my_printf (my_format ("", NULL)); + my_printf (my_format ("", NULL), i1); /* { dg-warning "too many" "null format_arg with arguments" } */ + + /* While my_printf allows a null argument, dgettext does not, so we expect + a null argument warning here. */ + my_printf (dgettext ("", NULL)); /* { dg-warning "null" "null format with dgettext" } */ +}
null-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: asm_fprintf-3.c =================================================================== --- asm_fprintf-3.c (nonexistent) +++ asm_fprintf-3.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", not defined, asm_fprintf format. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +void foo (int __gcc_host_wide_int__); +void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */
asm_fprintf-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-1.c =================================================================== --- miss-1.c (nonexistent) +++ miss-1.c (revision 154) @@ -0,0 +1,39 @@ +/* Test for warnings for missing format attributes. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +void +foo (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vprintf (fmt, ap); /* { dg-warning "candidate" "printf attribute warning" } */ + va_end (ap); +} + +void +bar (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vscanf (fmt, ap); /* { dg-warning "candidate" "scanf attribute warning" } */ + va_end (ap); +} + +__attribute__((__format__(__printf__, 1, 2))) void +foo2 (const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + vprintf (fmt, ap); + va_end (ap); +} + +void +vfoo (const char *fmt, va_list arg) +{ + vprintf (fmt, arg); /* { dg-warning "candidate" "printf attribute warning 2" } */ +}
miss-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: asm_fprintf-5.c =================================================================== --- asm_fprintf-5.c (nonexistent) +++ asm_fprintf-5.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", bad type, asm_fprintf format. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +typedef int __gcc_host_wide_int__; +void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as 'long' or 'long long'" } */
asm_fprintf-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: multattr-2.c =================================================================== --- multattr-2.c (nonexistent) +++ multattr-2.c (revision 154) @@ -0,0 +1,39 @@ +/* Test for multiple format attributes. Test for printf and scanf attributes + together, in different places on the declarations. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +/* If we specify multiple attributes for a single function, they should + all apply, wherever they are placed on the declarations. */ + +extern __attribute__((__format__(__printf__, 1, 0))) void + my_vprintf_scanf (const char *, va_list, const char *, ...) + __attribute__((__format__(__scanf__, 3, 4))); + +extern void (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf2) + (const char *, va_list, const char *, ...) + __attribute__((__format__(__scanf__, 3, 4))); + +extern __attribute__((__format__(__scanf__, 3, 4))) void + (__attribute__((__format__(__printf__, 1, 0))) my_vprintf_scanf3) + (const char *, va_list, const char *, ...); + +void +foo (va_list ap, int *ip, long *lp) +{ + my_vprintf_scanf ("%d", ap, "%d", ip); + my_vprintf_scanf ("%d", ap, "%ld", lp); + my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ + my_vprintf_scanf2 ("%d", ap, "%d", ip); + my_vprintf_scanf2 ("%d", ap, "%ld", lp); + my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ + my_vprintf_scanf3 ("%d", ap, "%d", ip); + my_vprintf_scanf3 ("%d", ap, "%ld", lp); + my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ +}
multattr-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-3.c =================================================================== --- miss-3.c (nonexistent) +++ miss-3.c (revision 154) @@ -0,0 +1,26 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { 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; +}
miss-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: no-y2k-1.c =================================================================== --- no-y2k-1.c (nonexistent) +++ no-y2k-1.c (revision 154) @@ -0,0 +1,12 @@ +/* Test for warnings for Y2K problems not being on by default. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + strftime (s, m, "%y%c%x", tp); +}
no-y2k-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-5.c =================================================================== --- miss-5.c (nonexistent) +++ miss-5.c (revision 154) @@ -0,0 +1,48 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { 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; +}
miss-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-1.c =================================================================== --- gcc_diag-1.c (nonexistent) +++ gcc_diag-1.c (revision 154) @@ -0,0 +1,242 @@ +/* Test for GCC diagnositc formats. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +#define ATTRIBUTE_DIAG(F) __attribute__ ((__format__ (F, 1, 2))) __attribute__ ((__nonnull__)); + +/* Magic identifiers must be set before the attribute is used. */ + +typedef long long __gcc_host_wide_int__; + +typedef struct location_s +{ + const char *file; + int line; +} location_t; + +union tree_node; +typedef union tree_node *tree; + +extern int diag (const char *, ...) ATTRIBUTE_DIAG(__gcc_diag__); +extern int tdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_tdiag__); +extern int cdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cdiag__); +extern int cxxdiag (const char *, ...) ATTRIBUTE_DIAG(__gcc_cxxdiag__); + +void +foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, + int *n, short int *hn, long int l, unsigned long int ul, + long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll, + ullong ull, unsigned int *un, const int *cn, signed char *ss, + unsigned char *us, const signed char *css, unsigned int u1, + unsigned int u2, location_t *loc, tree t1, union tree_node *t2, + tree *t3, tree t4[]) +{ + /* Acceptable C90 specifiers, flags and modifiers. */ + diag ("%%"); + tdiag ("%%"); + cdiag ("%%"); + cxxdiag ("%%"); + diag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + tdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + cdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + cxxdiag ("%d%i%o%u%x%c%s%p%%", i, i, u, u, u, i, s, p); + diag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p); + tdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p); + cdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p); + cxxdiag ("%qd%qi%qo%qu%qx%qc%qs%qp%<%%%'%>", i, i, u, u, u, i, s, p); + diag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + tdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + cdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + cxxdiag ("%ld%li%lo%lu%lx", l, l, ul, ul, ul); + diag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + tdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + cdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + cxxdiag ("%lld%lli%llo%llu%llx", ll, ll, ull, ull, ull); + diag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + tdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + cdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + cxxdiag ("%wd%wi%wo%wu%wx", ll, ll, ull, ull, ull); + diag ("%.*s", i, s); + tdiag ("%.*s", i, s); + cdiag ("%.*s", i, s); + cxxdiag ("%.*s", i, s); + + /* Extensions provided in the diagnostic framework. */ + diag ("%m"); + tdiag ("%m"); + cdiag ("%m"); + cxxdiag ("%m"); + diag ("%H", loc); + tdiag ("%H", loc); + cdiag ("%H", loc); + cxxdiag ("%H", loc); + diag ("%J", t1); + tdiag ("%J", t1); + cdiag ("%J", t1); + cxxdiag ("%J", t1); + + tdiag ("%D%F%T", t1, t1, t1); + tdiag ("%+D%+F%+T", t1, t1, t1); + tdiag ("%q+D%q+F%q+T", t1, t1, t1); + tdiag ("%D%D%D%D", t1, t2, *t3, t4[5]); + cdiag ("%D%F%T", t1, t1, t1); + cdiag ("%+D%+F%+T", t1, t1, t1); + cdiag ("%q+D%q+F%q+T", t1, t1, t1); + cdiag ("%D%D%D%D", t1, t2, *t3, t4[5]); + cdiag ("%E", t1); + cxxdiag ("%A%D%E%F%T%V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%D%D%D%D", t1, t2, *t3, t4[5]); + cxxdiag ("%#A%#D%#E%#F%#T%#V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%+A%+D%+E%+F%+T%+V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%+#A%+#D%+#E%+#F%+#T%+#V", t1, t1, t1, t1, t1, t1); + cxxdiag ("%C%L%O%P%Q", i, i, i, i, i); + + /* Bad stuff with extensions. */ + diag ("%m", i); /* { dg-warning "format" "extra arg" } */ + tdiag ("%m", i); /* { dg-warning "format" "extra arg" } */ + cdiag ("%m", i); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%m", i); /* { dg-warning "format" "extra arg" } */ + diag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + tdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%#m"); /* { dg-warning "format" "bogus modifier" } */ + diag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + tdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+m"); /* { dg-warning "format" "bogus modifier" } */ + diag ("%H"); /* { dg-warning "format" "missing arg" } */ + tdiag ("%H"); /* { dg-warning "format" "missing arg" } */ + cdiag ("%H"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%H"); /* { dg-warning "format" "missing arg" } */ + diag ("%J"); /* { dg-warning "format" "missing arg" } */ + tdiag ("%J"); /* { dg-warning "format" "missing arg" } */ + cdiag ("%J"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%J"); /* { dg-warning "format" "missing arg" } */ + diag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + tdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%H", i); /* { dg-warning "format" "wrong arg" } */ + diag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + tdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%H", p); /* { dg-warning "format" "wrong arg" } */ + diag ("%J", loc); /* { dg-warning "format" "wrong arg" } */ + tdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%J", loc); /* { dg-warning "format" "wrong arg" } */ + diag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + tdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%#H", loc); /* { dg-warning "format" "bogus modifier" } */ + diag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + tdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+H", loc); /* { dg-warning "format" "bogus modifier" } */ + diag ("%D", t1); /* { dg-warning "format" "bogus tree" } */ + tdiag ("%A", t1); /* { dg-warning "format" "bogus tree" } */ + tdiag ("%E", t1); /* { dg-warning "format" "bogus tree" } */ + tdiag ("%#D", t1); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%A", t1); /* { dg-warning "format" "bogus tree" } */ + cdiag ("%#D", t1); /* { dg-warning "format" "bogus modifier" } */ + cdiag ("%+D", t1); + cxxdiag ("%C"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%C", l); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%C", i, i); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%#C", i); /* { dg-warning "format" "bogus modifier" } */ + cxxdiag ("%+C", i); /* { dg-warning "format" "bogus modifier" } */ + tdiag ("%D"); /* { dg-warning "format" "missing arg" } */ + cdiag ("%D"); /* { dg-warning "format" "missing arg" } */ + cxxdiag ("%D"); /* { dg-warning "format" "missing arg" } */ + tdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */ + cdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */ + cxxdiag ("%D", i); /* { dg-warning "format" "wrong arg" } */ + tdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */ + cdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */ + cxxdiag ("%D", t1, t1); /* { dg-warning "format" "extra arg" } */ + + /* Standard specifiers not accepted in the diagnostic framework. */ + diag ("%X\n", u); /* { dg-warning "format" "HEX" } */ + diag ("%f\n", d); /* { dg-warning "format" "float" } */ + diag ("%e\n", d); /* { dg-warning "format" "float" } */ + diag ("%E\n", d); /* { dg-warning "format" "float" } */ + diag ("%g\n", d); /* { dg-warning "format" "float" } */ + diag ("%G\n", d); /* { dg-warning "format" "float" } */ + diag ("%n\n", n); /* { dg-warning "format" "counter" } */ + diag ("%hd\n", i); /* { dg-warning "format" "conversion" } */ + + /* Various tests of bad argument types. */ + diag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%-d", i); /* { dg-warning "format" "bad flag" } */ + diag ("% d", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("% d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("% d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("% d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + tdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + cdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%#o", u); /* { dg-warning "format" "bad flag" } */ + diag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%0d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%08d", i); /* { dg-warning "format" "bad flag" } */ + diag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%+d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%3d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%-3d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%.7d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + tdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + cdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%+9.4d\n", i); /* { dg-warning "format" "bad flag" } */ + diag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + tdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + cdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + cxxdiag ("%.3ld\n", l); /* { dg-warning "format" "bad flag" } */ + diag ("%d %lu\n", i, ul); + diag ("%d", l); /* { dg-warning "format" "bad argument types" } */ + diag ("%wd", l); /* { dg-warning "format" "bad argument types" } */ + diag ("%d", ll); /* { dg-warning "format" "bad argument types" } */ + diag ("%*s", i, s); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*.*s", i, i, s); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*d\n", i1, i); /* { dg-warning "format" "bad * argument types" } */ + diag ("%.*d\n", i2, i); /* { dg-warning "format" "bad * argument types" } */ + diag ("%*.*ld\n", i1, i2, l); /* { dg-warning "format" "bad * argument types" } */ + diag ("%ld", i); /* { dg-warning "format" "bad argument types" } */ + diag ("%s", n); /* { dg-warning "format" "bad argument types" } */ + + /* Wrong number of arguments. */ + diag ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */ + diag ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */ + /* Miscellaneous bogus constructions. */ + diag (""); /* { dg-warning "zero-length" "warning for empty format" } */ + diag ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ + diag ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */ + diag ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ + diag (NULL); /* { dg-warning "null" "null format string warning" } */ + diag ("%"); /* { dg-warning "trailing" "trailing % warning" } */ + diag ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ + diag ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ + + /* Make sure we still get warnings for regular printf. */ + printf ("%d\n", ll); /* { dg-warning "format" "bad argument types" } */ +}
gcc_diag-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-3.c =================================================================== --- gcc_diag-3.c (nonexistent) +++ gcc_diag-3.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test "tree", not + a type. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +int tree; +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'tree' is not defined as a type" } */
gcc_diag-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-5.c =================================================================== --- gcc_diag-5.c (nonexistent) +++ gcc_diag-5.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "location_t", not defined. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +void foo (int location_t); +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));
gcc_diag-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-7.c =================================================================== --- gcc_diag-7.c (nonexistent) +++ gcc_diag-7.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", not defined. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +void foo (int __gcc_host_wide_int__); +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));
gcc_diag-7.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-strftime-2.c =================================================================== --- c90-strftime-2.c (nonexistent) +++ c90-strftime-2.c (revision 154) @@ -0,0 +1,31 @@ +/* Test for strftime formats. Rejection of formats using C99 features in + pedantic C90 mode. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + strftime (s, m, "%C", tp); /* { dg-warning "C" "%C not in C90" } */ + strftime (s, m, "%D", tp); /* { dg-warning "C" "%D not in C90" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 13 } */ + strftime (s, m, "%e", tp); /* { dg-warning "C" "%e not in C90" } */ + strftime (s, m, "%F", tp); /* { dg-warning "C" "%F not in C90" } */ + strftime (s, m, "%g", tp); /* { dg-warning "C" "%g not in C90" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 17 } */ + strftime (s, m, "%G", tp); /* { dg-warning "C" "%G not in C90" } */ + strftime (s, m, "%h", tp); /* { dg-warning "C" "%h not in C90" } */ + strftime (s, m, "%n", tp); /* { dg-warning "C" "%n not in C90" } */ + strftime (s, m, "%r", tp); /* { dg-warning "C" "%r not in C90" } */ + strftime (s, m, "%R", tp); /* { dg-warning "C" "%R not in C90" } */ + strftime (s, m, "%t", tp); /* { dg-warning "C" "%t not in C90" } */ + strftime (s, m, "%T", tp); /* { dg-warning "C" "%T not in C90" } */ + strftime (s, m, "%u", tp); /* { dg-warning "C" "%u not in C90" } */ + strftime (s, m, "%V", tp); /* { dg-warning "C" "%V not in C90" } */ + strftime (s, m, "%z", tp); /* { dg-warning "C" "%z not in C90" } */ + strftime (s, m, "%EX", tp); /* { dg-warning "C" "%E not in C90" } */ + strftime (s, m, "%OW", tp); /* { dg-warning "C" "%O not in C90" } */ +}
c90-strftime-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-9.c =================================================================== --- gcc_diag-9.c (nonexistent) +++ gcc_diag-9.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", bad type. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +typedef int __gcc_host_wide_int__; +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as 'long' or 'long long'" } */
gcc_diag-9.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-printf-2.c =================================================================== --- c90-printf-2.c (nonexistent) +++ c90-printf-2.c (revision 154) @@ -0,0 +1,24 @@ +/* Test for printf formats. Formats using C99 features should be rejected + outside of C99 mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, double d, llong ll, intmax_t j, size_t z, ptrdiff_t t) +{ + /* Some tests already in c90-printf-1.c, e.g. %lf. */ + /* The widths hh, ll, j, z, t are new. */ + printf ("%hhd", i); /* { dg-warning "length|C" "%hh in C90" } */ + printf ("%lld", ll); /* { dg-warning "length|C" "%ll in C90" } */ + printf ("%jd", j); /* { dg-warning "length|C" "%j in C90" } */ + printf ("%zu", z); /* { dg-warning "length|C" "%z in C90" } */ + printf ("%td", t); /* { dg-warning "length|C" "%t in C90" } */ + /* The formats F, a, A are new. */ + printf ("%F", d); /* { dg-warning "C" "%F in C90" } */ + printf ("%a", d); /* { dg-warning "C" "%a in C90" } */ + printf ("%A", d); /* { dg-warning "C" "%A in C90" } */ +}
c90-printf-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: ext-2.c =================================================================== --- ext-2.c (nonexistent) +++ ext-2.c (revision 154) @@ -0,0 +1,73 @@ +/* Test for format extensions beyond the C standard and X/Open standard. + Test for scanf formats. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (quad_t *qp, u_quad_t *uqp, quad_t *qn, long long int *llp, + unsigned long long int *ullp, float *fp, char *s, void **pp, wchar_t *ls, + int *ip, unsigned int *up) +{ + /* As an extension, GCC allows the BSD length "q" for integer formats. + This is largely obsoleted in C99 by %j, %ll and SCNd64. + */ + scanf ("%qd%qi%qo%qu%qx%qX%qn", qp, qp, uqp, uqp, uqp, uqp, qn); + scanf ("%qf", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qF", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qe", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qE", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qg", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qG", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qa", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qA", fp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qs", s); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%q[abc]", s); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qc", s); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qp", pp); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qC", ls); /* { dg-warning "length" "bad use of %q" } */ + scanf ("%qS", ls); /* { dg-warning "length" "bad use of %q" } */ + /* As an extension, GCC allows the length "L" on integer formats + (but not %n) as a synonym for "ll". + This should be considered deprecated. + */ + scanf ("%Ld%Li%Lo%Lu%Lx%LX", llp, llp, ullp, ullp, ullp, ullp); + /* glibc also supports flags ' and I on scanf formats. The ' flag applies + to all formats scanning decimal values; the I flag only to decimal integer + formats. + */ + scanf ("%'d%'i%'u%'a%'A%'e%'E%'f%'F%'g%'G", ip, ip, up, fp, fp, fp, fp, + fp, fp, fp, fp); + scanf ("%'o", up); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'x", up); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'X", up); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'n", ip); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'s", s); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'[abc]", s); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'c", s); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'p", pp); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'C", ls); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%'S", ls); /* { dg-warning "flag" "bad use of ' flag" } */ + scanf ("%Id%Ii%Iu", ip, ip, up); + scanf ("%Ia", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IA", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Ie", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IE", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%If", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IF", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Ig", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IG", fp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Io", up); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Ix", up); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IX", up); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%In", ip); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Is", s); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%I[abc]", s); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Ic", s); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%Ip", pp); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IC", ls); /* { dg-warning "flag" "bad use of I flag" } */ + scanf ("%IS", ls); /* { dg-warning "flag" "bad use of I flag" } */ +}
ext-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: opt-2.c =================================================================== --- opt-2.c (nonexistent) +++ opt-2.c (revision 154) @@ -0,0 +1,7 @@ +/* Test diagnostics for options used on their own without + -Wformat. -Wformat-nonliteral. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat-nonliteral" } */ + +/* { dg-warning "warning: -Wformat-nonliteral ignored without -Wformat" "ignored" { target *-*-* } 0 } */
opt-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: ext-4.c =================================================================== --- ext-4.c (nonexistent) +++ ext-4.c (revision 154) @@ -0,0 +1,18 @@ +/* Test for scanf formats. %a extensions. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +#include "format.h" + +void +foo (char **sp, wchar_t **lsp) +{ + /* %a formats for allocation, only recognized in C90 mode, are a + GNU extension. Followed by other characters, %a is not treated + specially. + */ + scanf ("%as", sp); + scanf ("%aS", lsp); + scanf ("%a[bcd]", sp); +}
ext-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: no-exargs-1.c =================================================================== --- no-exargs-1.c (nonexistent) +++ no-exargs-1.c (revision 154) @@ -0,0 +1,14 @@ +/* Test for warnings for extra format arguments being disabled by + -Wno-format-extra-args. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */ + +#include "format.h" + +void +foo (int i) +{ + printf ("foo", i); + printf ("%1$d", i, i); +}
no-exargs-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: ext-6.c =================================================================== --- ext-6.c (nonexistent) +++ ext-6.c (revision 154) @@ -0,0 +1,47 @@ +/* Test for format extensions. Test that the C99 functions get their + default attributes in gnu89 mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +#include "format.h" + +void +foo (int i, char *s, size_t n, int *ip, va_list v0, va_list v1, va_list v2, + va_list v3, va_list v4, va_list v5, va_list v6, va_list v7, va_list v8, + va_list v9, va_list v10, va_list v11, va_list v12, va_list v13) +{ + fprintf (stdout, "%d", i); + fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ + printf ("%d", i); + printf ("%ld", i); /* { dg-warning "format" "printf" } */ + fprintf_unlocked (stdout, "%d", i); + fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "fprintf_unlocked" } */ + printf_unlocked ("%d", i); + printf_unlocked ("%ld", i); /* { dg-warning "format" "printf_unlocked" } */ + sprintf (s, "%d", i); + sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ + snprintf (s, n, "%d", i); + snprintf (s, n, "%ld", i); /* { dg-warning "format" "snprintf" } */ + vfprintf (stdout, "%d", v0); + vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */ + vprintf ("%d", v2); + vprintf ("%Y", v3); /* { dg-warning "format" "vprintf" } */ + vsprintf (s, "%d", v4); + vsprintf (s, "%Y", v5); /* { dg-warning "format" "vsprintf" } */ + vsnprintf (s, n, "%d", v6); + vsnprintf (s, n, "%Y", v7); /* { dg-warning "format" "vsnprintf" } */ + fscanf (stdin, "%d", ip); + fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */ + scanf ("%d", ip); + scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */ + sscanf (s, "%d", ip); + sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */ + vfscanf (stdin, "%d", v8); + vfscanf (stdin, "%Y", v9); /* { dg-warning "format" "vfscanf" } */ + vscanf ("%d", v10); + vscanf ("%Y", v11); /* { dg-warning "format" "vscanf" } */ + vsscanf (s, "%d", v12); + vsscanf (s, "%Y", v13); /* { dg-warning "format" "vsscanf" } */ +}
ext-6.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: opt-4.c =================================================================== --- opt-4.c (nonexistent) +++ opt-4.c (revision 154) @@ -0,0 +1,7 @@ +/* Test diagnostics for options used on their own without + -Wformat. -Wformat-y2k. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat-y2k" } */ + +/* { dg-warning "warning: -Wformat-y2k ignored without -Wformat" "ignored" { target *-*-* } 0 } */
opt-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-2.c =================================================================== --- attr-2.c (nonexistent) +++ attr-2.c (revision 154) @@ -0,0 +1,67 @@ +/* Test for format attributes: test use of __attribute__. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +extern void tformatprintf (const char *, ...) __attribute__((format(printf, 1, 2))); +extern void tformat__printf__ (const char *, ...) __attribute__((format(__printf__, 1, 2))); +extern void tformatscanf (const char *, ...) __attribute__((format(scanf, 1, 2))); +extern void tformat__scanf__ (const char *, ...) __attribute__((format(__scanf__, 1, 2))); +extern void tformatstrftime (const char *) __attribute__((format(strftime, 1, 0))); +extern void tformat__strftime__ (const char *) __attribute__((format(__strftime__, 1, 0))); +extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2))); +extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2))); +extern void t__format__printf (const char *, ...) __attribute__((__format__(printf, 1, 2))); +extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__printf__, 1, 2))); +extern void t__format__scanf (const char *, ...) __attribute__((__format__(scanf, 1, 2))); +extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__scanf__, 1, 2))); +extern void t__format__strftime (const char *) __attribute__((__format__(strftime, 1, 0))); +extern void t__format____strftime__ (const char *) __attribute__((__format__(__strftime__, 1, 0))); +extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2))); +extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2))); + +extern char *tformat_arg (const char *) __attribute__((format_arg(1))); +extern char *t__format_arg__ (const char *) __attribute__((__format_arg__(1))); + +void +foo (int i, int *ip, double d) +{ + tformatprintf ("%d", i); + tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */ + tformat__printf__ ("%d", i); + tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */ + tformatscanf ("%d", ip); + tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */ + tformat__scanf__ ("%d", ip); + tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */ + tformatstrftime ("%a"); + tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */ + tformat__strftime__ ("%a"); + tformat__strftime__ ("%"); /* { dg-warning "format" "attribute format __strftime__" } */ + tformatstrfmon ("%n", d); + tformatstrfmon ("%"); /* { dg-warning "format" "attribute format strfmon" } */ + tformat__strfmon__ ("%n", d); + tformat__strfmon__ ("%"); /* { dg-warning "format" "attribute format __strfmon__" } */ + t__format__printf ("%d", i); + t__format__printf ("%"); /* { dg-warning "format" "attribute __format__ printf" } */ + t__format____printf__ ("%d", i); + t__format____printf__ ("%"); /* { dg-warning "format" "attribute __format__ __printf__" } */ + t__format__scanf ("%d", ip); + t__format__scanf ("%"); /* { dg-warning "format" "attribute __format__ scanf" } */ + t__format____scanf__ ("%d", ip); + t__format____scanf__ ("%"); /* { dg-warning "format" "attribute __format__ __scanf__" } */ + t__format__strftime ("%a"); + t__format__strftime ("%"); /* { dg-warning "format" "attribute __format__ strftime" } */ + t__format____strftime__ ("%a"); + t__format____strftime__ ("%"); /* { dg-warning "format" "attribute __format__ __strftime__" } */ + t__format__strfmon ("%n", d); + t__format__strfmon ("%"); /* { dg-warning "format" "attribute __format__ strfmon" } */ + t__format____strfmon__ ("%n", d); + t__format____strfmon__ ("%"); /* { dg-warning "format" "attribute __format__ __strfmon__" } */ + tformatprintf (tformat_arg ("%d"), i); + tformatprintf (tformat_arg ("%")); /* { dg-warning "format" "attribute format_arg" } */ + tformatprintf (t__format_arg__ ("%d"), i); + tformatprintf (t__format_arg__ ("%")); /* { dg-warning "format" "attribute __format_arg__" } */ +}
attr-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-4.c =================================================================== --- attr-4.c (nonexistent) +++ attr-4.c (revision 154) @@ -0,0 +1,25 @@ +/* Test for format attributes: test use of __attribute__ + in prefix attributes. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +extern __attribute__((format(printf, 1, 2))) void tformatprintf0 (const char *, ...); +extern void __attribute__((format(printf, 1, 2))) tformatprintf1 (const char *, ...); +extern void foo (void), __attribute__((format(printf, 1, 2))) tformatprintf2 (const char *, ...); +extern __attribute__((noreturn)) void bar (void), __attribute__((format(printf, 1, 2))) tformatprintf3 (const char *, ...); + +void +baz (int i, int *ip, double d) +{ + tformatprintf0 ("%d", i); + tformatprintf0 ("%"); /* { dg-warning "format" "attribute format printf case 0" } */ + tformatprintf1 ("%d", i); + tformatprintf1 ("%"); /* { dg-warning "format" "attribute format printf case 1" } */ + tformatprintf2 ("%d", i); + tformatprintf2 ("%"); /* { dg-warning "format" "attribute format printf case 2" } */ + tformatprintf3 ("%d", i); + tformatprintf3 ("%"); /* { dg-warning "format" "attribute format printf case 3" } */ +}
attr-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-6.c =================================================================== --- attr-6.c (nonexistent) +++ attr-6.c (revision 154) @@ -0,0 +1,22 @@ +/* Test for format attributes: test default attributes are applied + to implicit declarations. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +/* We can't #include "format.h" here. */ + +/* Technically, none of the format functions should be implicitly declared; + either the implicit type is wrong, the function has variable arguments + or it requires a type declared in a header. However, some bad programming + practice uses implicit declarations of some of these functions. + + Note that printf is not used in this test because of the declaration + of it as a built-in function. */ + +void +foo (const char *s, int *p) +{ + scanf("%ld", p); /* { dg-warning "format" "implicit scanf" } */ + /* { dg-warning "implicit" "implicit decl warning" { target *-*-* } 20 } */ +}
attr-6.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: plus-1.c =================================================================== --- plus-1.c (nonexistent) +++ plus-1.c (revision 154) @@ -0,0 +1,20 @@ +/* Test for printf formats using string literal plus constant. + */ +/* Origin: Jakub Jelinek */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat=2" } */ + +#include "format.h" + +void +foo (int i) +{ + printf ("%%d\n" + 1, i); + printf (5 + "%.-*d%3d\n", i); + printf ("%d%d" + 2, i, i); /* { dg-warning "arguments" "wrong number of args" } */ + printf (3 + "%d\n"); /* { dg-warning "zero-length" "zero-length string" } */ + printf ("%d\n" + i, i); /* { dg-warning "not a string" "non-constant addend" } */ + printf ("%d\n" + 10); /* { dg-warning "not a string" "too large addend" } */ + printf ("%d\n" - 1, i); /* { dg-warning "not a string" "minus constant" } */ + printf ("%d\n" + -1, i); /* { dg-warning "not a string" "negative addend" } */ +}
plus-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-scanf-2.c =================================================================== --- c90-scanf-2.c (nonexistent) +++ c90-scanf-2.c (revision 154) @@ -0,0 +1,25 @@ +/* Test for scanf formats. Formats using C99 features should be rejected + outside of C99 mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (signed char *hhp, float *fp, llong *llp, intmax_t *jp, + size_t *zp, ptrdiff_t *tp) +{ + /* Some tests already in c90-scanf-1.c. */ + /* The widths hh, ll, j, z, t are new. */ + scanf ("%hhd", hhp); /* { dg-warning "length|C" "%hh in C90" } */ + scanf ("%lld", llp); /* { dg-warning "length|C" "%ll in C90" } */ + scanf ("%jd", jp); /* { dg-warning "length|C" "%j in C90" } */ + scanf ("%zu", zp); /* { dg-warning "length|C" "%z in C90" } */ + scanf ("%td", tp); /* { dg-warning "length|C" "%t in C90" } */ + /* The formats F, a, A are new. */ + scanf ("%F", fp); /* { dg-warning "C" "%F in C90" } */ + scanf ("%a", fp); /* { dg-warning "C" "%a in C90" } */ + scanf ("%A", fp); /* { dg-warning "C" "%A in C90" } */ +}
c90-scanf-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-scanf-4.c =================================================================== --- c90-scanf-4.c (nonexistent) +++ c90-scanf-4.c (revision 154) @@ -0,0 +1,33 @@ +/* Test for scanf formats. Test that the C90 functions get their default + attributes in strict C90 mode, but the C99 and gettext functions + do not. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3, + va_list v4, va_list v5) +{ + fscanf (stdin, "%d", ip); + fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */ + scanf ("%d", ip); + scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */ + sscanf (s, "%d", ip); + sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */ + vfscanf (stdin, "%d", v0); + vfscanf (stdin, "%Y", v1); + vscanf ("%d", v2); + vscanf ("%Y", v3); + vsscanf (s, "%d", v4); + vsscanf (s, "%Y", v5); + scanf (gettext ("%d"), ip); + scanf (gettext ("%ld"), ip); + scanf (dgettext ("", "%d"), ip); + scanf (dgettext ("", "%ld"), ip); + scanf (dcgettext ("", "%d", 0), ip); + scanf (dcgettext ("", "%ld", 0), ip); +}
c90-scanf-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: xopen-1.c =================================================================== --- xopen-1.c (nonexistent) +++ xopen-1.c (revision 154) @@ -0,0 +1,125 @@ +/* Test for X/Open format extensions, as found in the + Single Unix Specification and in Austin Group draft 7. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (int i, unsigned int u, wint_t lc, wchar_t *ls, int *ip, double d, + char *s, void *p, int *n, long int l, int i2, float *fp, long int *lp, + va_list va) +{ + /* The conversion specifiers C and S, for both printf and scanf, + are X/Open extensions. + */ + printf ("%C", lc); + printf ("%3C", lc); + printf ("%.3C", lc); /* { dg-warning "precision" "precision with %C" } */ + printf ("%hC", lc); /* { dg-warning "length" "bad %hC" } */ + printf ("%hhC", lc); /* { dg-warning "length" "bad %hhC" } */ + printf ("%lC", lc); /* { dg-warning "length" "bad %lC" } */ + printf ("%llC", lc); /* { dg-warning "length" "bad %llC" } */ + printf ("%jC", lc); /* { dg-warning "length" "bad %jC" } */ + printf ("%zC", lc); /* { dg-warning "length" "bad %zC" } */ + printf ("%tC", lc); /* { dg-warning "length" "bad %tC" } */ + printf ("%LC", lc); /* { dg-warning "length" "bad %LC" } */ + printf ("%-C", lc); + printf ("%+C", lc); /* { dg-warning "flag" "bad %+C" } */ + printf ("% C", lc); /* { dg-warning "flag" "bad % C" } */ + printf ("%#C", lc); /* { dg-warning "flag" "bad %#C" } */ + printf ("%0C", lc); /* { dg-warning "flag" "bad %0C" } */ + printf ("%'C", lc); /* { dg-warning "flag" "bad %'C" } */ + printf ("%S", ls); + printf ("%3S", ls); + printf ("%.3S", ls); + printf ("%hS", ls); /* { dg-warning "length" "bad %hS" } */ + printf ("%hhS", ls); /* { dg-warning "length" "bad %hhS" } */ + printf ("%lS", ls); /* { dg-warning "length" "bad %lS" } */ + printf ("%llS", ls); /* { dg-warning "length" "bad %llS" } */ + printf ("%jS", ls); /* { dg-warning "length" "bad %jS" } */ + printf ("%zS", ls); /* { dg-warning "length" "bad %zS" } */ + printf ("%tS", ls); /* { dg-warning "length" "bad %tS" } */ + printf ("%LS", ls); /* { dg-warning "length" "bad %LS" } */ + printf ("%-S", ls); + printf ("%+S", ls); /* { dg-warning "flag" "bad %+S" } */ + printf ("% S", ls); /* { dg-warning "flag" "bad % S" } */ + printf ("%#S", ls); /* { dg-warning "flag" "bad %#S" } */ + printf ("%0S", ls); /* { dg-warning "flag" "bad %0S" } */ + printf ("%'S", ls); /* { dg-warning "flag" "bad %'S" } */ + scanf ("%C", ls); + scanf ("%S", ls); + scanf ("%*C%*S"); + scanf ("%2C%3S", ls, ls); + scanf ("%hC", ls); /* { dg-warning "length" "bad %hC" } */ + scanf ("%hhC", ls); /* { dg-warning "length" "bad %hhC" } */ + scanf ("%lC", ls); /* { dg-warning "length" "bad %lC" } */ + scanf ("%llC", ls); /* { dg-warning "length" "bad %llC" } */ + scanf ("%jC", ls); /* { dg-warning "length" "bad %jC" } */ + scanf ("%zC", ls); /* { dg-warning "length" "bad %zC" } */ + scanf ("%tC", ls); /* { dg-warning "length" "bad %tC" } */ + scanf ("%LC", ls); /* { dg-warning "length" "bad %LC" } */ + scanf ("%hS", ls); /* { dg-warning "length" "bad %hS" } */ + scanf ("%hhS", ls); /* { dg-warning "length" "bad %hhS" } */ + scanf ("%lS", ls); /* { dg-warning "length" "bad %lS" } */ + scanf ("%llS", ls); /* { dg-warning "length" "bad %llS" } */ + scanf ("%jS", ls); /* { dg-warning "length" "bad %jS" } */ + scanf ("%zS", ls); /* { dg-warning "length" "bad %zS" } */ + scanf ("%tS", ls); /* { dg-warning "length" "bad %tS" } */ + scanf ("%LS", ls); /* { dg-warning "length" "bad %LS" } */ + /* In C99 mode (even with extensions), %aS is a floating point + format followed by an S. + */ + scanf ("%aS", fp); + /* The printf flag character ' is an X/Open extension. */ + printf ("%'d%'i%'u%'f%'F%'g%'G", i, i, u, d, d, d, d); + printf ("%'o", u); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'x", u); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'X", u); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'e", d); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'E", d); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'a", d); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'A", d); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'c", i); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'s", s); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'p", p); /* { dg-warning "flag" "bad use of ' flag" } */ + printf ("%'n", n); /* { dg-warning "flag" "bad use of ' flag" } */ + /* 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|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); + printf ("%1$d%d", i, i); /* { dg-warning "missing" "mixing $ and non-$ formats" } */ + printf ("%%%1$d%%%2$d", i, i); + printf ("%d%2$d", i); /* { dg-warning "used after format" "mixing $ and non-$ formats" } */ + printf ("%1$*d", i, i); /* { dg-warning "missing" "mixing $ and non-$ formats" } */ + printf ("%*1$d", i); /* { dg-warning "missing" "mixing $ and non-$ formats" } */ + scanf ("%1$d%d", ip, ip); /* { dg-warning "missing" "mixing $ and non-$ formats" } */ + scanf ("%*f%%%1$d%%%2$d", ip, ip); + printf ("%2$d", i); /* { dg-warning "operand" "$ number too large" } */ + printf ("%0$d", i); /* { dg-warning "operand" "$ number too small" } */ + printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */ + printf ("%2$d%1$d", i, i, i); /* { dg-warning "unused" "unused $ operand" } */ + vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */ + /* With scanf formats, gaps in the used arguments are allowed only if the + arguments are all pointers. In such a case, should only give the lesser + warning about unused arguments rather than the more serious one about + argument gaps. */ + scanf ("%3$d%1$d", ip, ip, ip); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */ + /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 112 } */ + /* If there are non-pointer arguments unused at the end, this is also OK. */ + scanf ("%3$d%1$d", ip, ip, ip, i); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */ + /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 115 } */ + scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */ + /* Can't check the arguments in the vscanf case, so should suppose the + lesser problem. */ + vscanf ("%3$d%1$d", va); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */ + /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 120 } */ + scanf ("%2$*d%1$d", ip, ip); /* { dg-warning "operand" "operand number with suppression" } */ + printf ("%1$d%1$d", i); + scanf ("%1$d%1$d", ip); /* { dg-warning "more than once" "multiple use of scanf argument" } */ +}
xopen-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: strfmon-2.c =================================================================== --- strfmon-2.c (nonexistent) +++ strfmon-2.c (revision 154) @@ -0,0 +1,13 @@ +/* Test for strfmon format checking. Test for missing fill character + at end of format. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (char *s, size_t m) +{ + strfmon (s, m, "%="); /* { dg-warning "missing fill character at end" } */ +}
strfmon-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: cast-1.c =================================================================== --- cast-1.c (nonexistent) +++ cast-1.c (revision 154) @@ -0,0 +1,16 @@ +/* Test for strings cast through integer types: should not be treated + as format strings unless the types are of the same width as + pointers (intptr_t or similar). */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +void +f (int x) +{ + printf("%s", x); /* { dg-warning "format" } */ + printf((char *)(size_t)"%s", x); /* { dg-warning "format" } */ + printf((char *)(char)"%s", x); /* { dg-warning "warning: cast from pointer to integer of different size" } */ +}
cast-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: xopen-3.c =================================================================== --- xopen-3.c (nonexistent) +++ xopen-3.c (revision 154) @@ -0,0 +1,15 @@ +/* Test for warnings for $ operand numbers after ordinary formats. + Bug c/15444 from james-gcc-bugzilla-501qll3d at and dot org. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (int i) +{ + printf ("%d%2$d", i); /* { dg-warning "used after format" "mixing $ and non-$ formats" } */ + printf ("%d%*1$d", i, i); /* { dg-warning "used after format" "mixing $ and non-$ formats" } */ + printf ("%d%.*1$d", i, i); /* { dg-warning "used after format" "mixing $ and non-$ formats" } */ +}
xopen-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-scanf-1.c =================================================================== --- c99-scanf-1.c (nonexistent) +++ c99-scanf-1.c (revision 154) @@ -0,0 +1,145 @@ +/* Test for scanf formats. Formats using C99 features, including cases + where C99 specifies some aspect of the format to be ignored or where + the behavior is undefined. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp, + signed char *hhp, unsigned char *uhhp, long int *lp, + unsigned long int *ulp, float *fp, double *dp, long double *ldp, char *s, + void **pp, int *n, long long *llp, unsigned long long *ullp, wchar_t *ls, + short int *hn, signed char *hhn, long int *ln, long long int *lln, + intmax_t *jp, uintmax_t *ujp, intmax_t *jn, size_t *zp, + signed_size_t *szp, signed_size_t *zn, ptrdiff_t *tp, + unsigned_ptrdiff_t *utp, ptrdiff_t *tn) +{ + /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.2 (pages 281-288). + We do not repeat here most of the checks for correct C90 formats + or completely broken formats. + */ + /* Valid, invalid and silly assignment-suppression + and width constructions. + */ + scanf ("%*d%*i%*o%*u%*x%*X%*a%*A%*e%*E%*f%*F%*g%*G%*s%*[abc]%*c%*p"); + scanf ("%*2d%*8s%*3c"); + scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */ + scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */ + scanf ("%2d%3i%4o%5u%6x%7X%8a%9A%10e%11E%12f%13F%14g%15G%16s%3[abc]%4c%5p", + ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, fp, fp, fp, + s, s, s, pp); + scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */ + scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */ + /* Valid and invalid %h, %hh, %l, %ll, %j, %z, %t, %L constructions. */ + scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn); + scanf ("%ha", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hA", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hF", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hs", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hc", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hhd%hhi%hho%hhu%hhx%hhX%hhn", hhp, hhp, uhhp, uhhp, uhhp, uhhp, + hhn); + scanf ("%hha", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhA", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhe", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhE", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhf", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhF", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhg", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhG", fp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhs", s); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hh[ac]", s); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhc", s); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%hhp", pp); /* { dg-warning "length" "bad use of %hh" } */ + scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln); + scanf ("%la%lA%le%lE%lf%lF%lg%lG", dp, dp, dp, dp, dp, dp, dp, dp); + scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */ + scanf ("%ls", ls); + scanf ("%l[ac]", ls); + scanf ("%lc", ls); + scanf ("%lld%lli%llo%llu%llx%llX%lln", llp, llp, ullp, ullp, ullp, ullp, + lln); + scanf ("%lla", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llA", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%lle", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llE", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llf", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llF", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llg", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llG", fp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%lls", s); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%ll[ac]", s); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llc", s); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%llp", pp); /* { dg-warning "length" "bad use of %ll" } */ + scanf ("%jd%ji%jo%ju%jx%jX%jn", jp, jp, ujp, ujp, ujp, ujp, jn); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */ + scanf ("%ja", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jA", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%je", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jE", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jf", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jF", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jg", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jG", fp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%js", s); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%j[ac]", s); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jc", s); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%jp", pp); /* { dg-warning "length" "bad use of %j" } */ + scanf ("%zd%zi%zo%zu%zx%zX%zn", szp, szp, zp, zp, zp, zp, zn); + scanf ("%za", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zA", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%ze", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zE", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zf", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zF", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zg", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zG", fp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zs", s); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%z[ac]", s); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zc", s); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%zp", pp); /* { dg-warning "length" "bad use of %z" } */ + scanf ("%td%ti%to%tu%tx%tX%tn", tp, tp, utp, utp, utp, utp, tn); + scanf ("%ta", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tA", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%te", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tE", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tf", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tF", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tg", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tG", fp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%ts", s); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%t[ac]", s); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tc", s); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%tp", pp); /* { dg-warning "length" "bad use of %t" } */ + scanf ("%La%LA%Le%LE%Lf%LF%Lg%LG", ldp, ldp, ldp, ldp, ldp, ldp, ldp, ldp); + scanf ("%Ld", llp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Li", llp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lo", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lu", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lx", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%LX", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Ls", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%L[ac]", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Lc", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Lp", pp); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Ln", n); /* { dg-warning "length" "bad use of %L" } */ + /* Valid uses of each bare conversion. */ + scanf ("%d%i%o%u%x%X%a%A%e%E%f%F%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip, + uip, fp, fp, fp, fp, fp, fp, fp, fp, s, s, s, pp, n); + /* Assert that %as is not treated as an extension in C99 mode. */ + scanf ("%as", fp); + scanf ("%a[", fp); + /* Tests for bad argument types: pointer target sign with %hh. */ + scanf ("%hhd", uhhp); /* { dg-warning "format" "%hhd sign" } */ + scanf ("%hhu", hhp); /* { dg-warning "format" "%hhu sign" } */ +}
c99-scanf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: branch-1.c =================================================================== --- branch-1.c (nonexistent) +++ branch-1.c (revision 154) @@ -0,0 +1,27 @@ +/* Test for format checking of conditional expressions. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +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" "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" "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 } */ +}
branch-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-scanf-3.c =================================================================== --- c99-scanf-3.c (nonexistent) +++ c99-scanf-3.c (revision 154) @@ -0,0 +1,32 @@ +/* Test for scanf formats. Test that the C99 functions get their default + attributes in strict C99 mode, but the gettext functions do not. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int *ip, char *s, va_list v0, va_list v1, va_list v2, va_list v3, + va_list v4, va_list v5) +{ + fscanf (stdin, "%d", ip); + fscanf (stdin, "%ld", ip); /* { dg-warning "format" "fscanf" } */ + scanf ("%d", ip); + scanf ("%ld", ip); /* { dg-warning "format" "scanf" } */ + sscanf (s, "%d", ip); + sscanf (s, "%ld", ip); /* { dg-warning "format" "sscanf" } */ + vfscanf (stdin, "%d", v0); + vfscanf (stdin, "%Y", v1); /* { dg-warning "format" "vfscanf" } */ + vscanf ("%d", v2); + vscanf ("%Y", v3); /* { dg-warning "format" "vscanf" } */ + vsscanf (s, "%d", v4); + vsscanf (s, "%Y", v5); /* { dg-warning "format" "vsscanf" } */ + scanf (gettext ("%d"), ip); + scanf (gettext ("%ld"), ip); + scanf (dgettext ("", "%d"), ip); + scanf (dgettext ("", "%ld"), ip); + scanf (dcgettext ("", "%d", 0), ip); + scanf (dcgettext ("", "%ld", 0), ip); +}
c99-scanf-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: zero-length-1.c =================================================================== --- zero-length-1.c (nonexistent) +++ zero-length-1.c (revision 154) @@ -0,0 +1,15 @@ +/* Test the -Wno-format-zero-length option, which suppresses warnings + about zero-length formats. */ +/* Origin: Jason Thorpe */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-format-zero-length" } */ + +#include "format.h" + +void +foo (void) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */ + /* Zero-length format strings are allowed. */ + printf (""); +}
zero-length-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-strftime-2.c =================================================================== --- c99-strftime-2.c (nonexistent) +++ c99-strftime-2.c (revision 154) @@ -0,0 +1,23 @@ +/* Test for strftime formats. Rejection of extensions in pedantic mode. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + /* %P is a lowercase version of %p. */ + strftime (s, m, "%P", tp); /* { dg-warning "C" "strftime %P" } */ + /* %k is %H but padded with a space rather than 0 if necessary. */ + strftime (s, m, "%k", tp); /* { dg-warning "C" "strftime %k" } */ + /* %l is %I but padded with a space rather than 0 if necessary. */ + strftime (s, m, "%l", tp); /* { dg-warning "C" "strftime %l" } */ + /* %s is the number of seconds since the Epoch. */ + strftime (s, m, "%s", tp); /* { dg-warning "C" "strftime %s" } */ + /* Extensions using %O already tested in c99-strftime-1.c. */ + /* Width and flags are GNU extensions for strftime. */ + strftime (s, m, "%20Y", tp); /* { dg-warning "C" "strftime width" } */ + strftime (s, m, "%^A", tp); /* { dg-warning "C" "strftime flags" } */ +}
c99-strftime-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: dfp-scanf-1.c =================================================================== --- dfp-scanf-1.c (nonexistent) +++ dfp-scanf-1.c (revision 154) @@ -0,0 +1,99 @@ +/* Test for scanf formats for Decimal Floating Point types. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target dfp } */ +/* { dg-options "-Wformat" } */ + + +#include "format.h" + +void +voo (_Decimal32 *x, _Decimal64 *y, _Decimal128 *z, int *i, unsigned int *j, + double *d, char **p) +{ + /* See ISO/IEC DTR 24732 subclause 9.3 (currently Working Draft 5 from + 2005-03-06). */ + /* Formatted input/output specifiers. */ + + /* Check lack of warnings for valid usage. */ + + scanf ("%Hf", x); + scanf ("%HF", x); + scanf ("%He", x); + scanf ("%HE", x); + scanf ("%Hg", x); + scanf ("%HG", x); + + scanf ("%Df", y); + scanf ("%DF", y); + scanf ("%De", y); + scanf ("%DE", y); + scanf ("%Dg", y); + scanf ("%DG", y); + + scanf ("%DDf", z); + scanf ("%DDF", z); + scanf ("%DDe", z); + scanf ("%DDE", z); + scanf ("%DDg", z); + scanf ("%DDG", z); + + scanf ("%DG%DDE%HF%DDe%He%HE%DF%DDF%De%DDG%HG%Df%Hg%DE%DDf%Dg%DDg%Hf\n", + y, z, x, z, x, x, y, z, y, z, x, y, x, y, z, y, z, x); + + /* Check warnings for type mismatches. */ + + scanf ("%Hf", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HF", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%He", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HE", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%Hg", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HG", y); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%Hf", z); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HF", z); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%He", z); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HE", z); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%Hg", z); /* { dg-warning "expects type" "bad use of %H" } */ + scanf ("%HG", z); /* { dg-warning "expects type" "bad use of %H" } */ + + scanf ("%Df", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DF", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%De", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DE", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%Dg", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DG", x); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%Df", z); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DF", z); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%De", z); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DE", z); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%Dg", z); /* { dg-warning "expects type" "bad use of %D" } */ + scanf ("%DG", z); /* { dg-warning "expects type" "bad use of %D" } */ + + scanf ("%DDf", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDF", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDe", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDE", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDg", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDG", x); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDf", y); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDF", y); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDe", y); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDE", y); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDg", y); /* { dg-warning "expects type" "bad use of %DD" } */ + scanf ("%DDG", y); /* { dg-warning "expects type" "bad use of %DD" } */ + + /* Check for warnings for bad use of H, D, and DD length specifiers. */ + + scanf ("%Hd\n", i); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hi\n", i); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Ho\n", j); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hu\n", j); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hx\n", j); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%HX\n", j); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Ha\n", d); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%HA\n", d); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hc\n", i); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hs\n", p); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hp\n", p); /* { dg-warning "length" "bad use of %H" } */ + scanf ("%Hn\n", p); /* { dg-warning "length" "bad use of %H" } */ +}
dfp-scanf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: cmn-err-1.c =================================================================== --- cmn-err-1.c (nonexistent) +++ cmn-err-1.c (revision 154) @@ -0,0 +1,38 @@ +/* { dg-do compile { target *-*-solaris2.* } } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +void cmn_err_func (int level, char * format, ...) + __attribute__((format (cmn_err, 2, 3))); + +void cmn_err_func (int level, char * format, ...) +{ +} + +const char *string = "foo"; + +int main() +{ + int i = 1; + long l = 2; + llong ll = 3; + + cmn_err_func (0, "%s", string); + cmn_err_func (0, "%d %D %o %O %x %X %u", i, i, i, i, i, i, i); + cmn_err_func (0, "%ld %lD %lo %lO %lx %lX %lu", l, l, l, l, l, l, l); + cmn_err_func (0, "%lld %llD %llo %llO %llx %llX %llu", + ll, ll, ll, ll, ll, ll, ll); + cmn_err_func (0, "%b %s", i, "\01Foo", string); + cmn_err_func (0, "%p", string); + cmn_err_func (0, "%16b", i, "\01Foo"); + + cmn_err_func (0, "%i", i); /* { dg-error "unknown|too many" } */ + cmn_err_func (0, "%d", l); /* { dg-error "expects type" } */ + cmn_err_func (0, "%b"); /* { dg-error "too few" } */ + cmn_err_func (0, "%b", i); /* { dg-error "too few" } */ + cmn_err_func (0, "%b", i, i); /* { dg-error "expects type" } */ + cmn_err_func (0, "%b", string, i); /* { dg-error "expects type" } */ + cmn_err_func (0, "%p", 3); /* { dg-error "expects type" } */ + return 0; +}
cmn-err-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-printf-1.c =================================================================== --- c99-printf-1.c (nonexistent) +++ c99-printf-1.c (revision 154) @@ -0,0 +1,197 @@ +/* Test for printf formats. Formats using C99 features, including cases + where C99 specifies some aspect of the format to be ignored or where + the behavior is undefined. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, unsigned int u, double d, char *s, void *p, int *n, + long double ld, wint_t lc, wchar_t *ls, long long int ll, + unsigned long long int ull, signed char *ss, unsigned char *us, + long long int *lln, intmax_t j, uintmax_t uj, intmax_t *jn, + size_t z, signed_size_t sz, signed_size_t *zn, + ptrdiff_t t, ptrdiff_t *tn) +{ + /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.1 (pages 273-281). + We do not repeat here most of the checks for correct C90 formats + or completely broken formats. + */ + /* Valid and invalid %h, %hh, %l, %ll, %j, %z, %t, %L constructions. */ + printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hF", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%ha", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hA", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hc", i); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hs", s); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hhd%hhi%hho%hhu%hhx%hhX", i, i, u, u, u, u); + printf ("%hhn", ss); + printf ("%hhf", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhF", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhe", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhE", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhg", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhG", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hha", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhA", d); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhc", i); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhs", s); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%hhp", p); /* { dg-warning "length" "bad use of %hh" } */ + printf ("%lc", lc); + printf ("%ls", ls); + printf ("%lf%lF%le%lE%lg%lG%la%lA", d, d, d, d, d, d, d, d); + printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%lld%lli%llo%llu%llx%llX", ll, ll, ull, ull, ull, ull); + printf ("%lln", lln); + printf ("%llf", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llF", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%lle", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llE", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llg", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llG", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%lla", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llA", d); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llc", i); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%lls", s); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%llp", p); /* { dg-warning "length" "bad use of %ll" } */ + printf ("%jd%ji%jo%ju%jx%jX", j, j, uj, uj, uj, uj); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */ + printf ("%jn", jn); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */ + printf ("%jf", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jF", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%je", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jE", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jg", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jG", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%ja", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jA", d); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jc", i); /* { dg-warning "length" "bad use of %j" } */ + printf ("%js", s); /* { dg-warning "length" "bad use of %j" } */ + printf ("%jp", p); /* { dg-warning "length" "bad use of %j" } */ + printf ("%zd%zi%zo%zu%zx%zX", sz, sz, z, z, z, z); + printf ("%zn", zn); + printf ("%zf", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zF", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%ze", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zE", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zg", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zG", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%za", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zA", d); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zc", i); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zs", s); /* { dg-warning "length" "bad use of %z" } */ + printf ("%zp", p); /* { dg-warning "length" "bad use of %z" } */ + printf ("%td%ti%to%tu%tx%tX", t, t, t, t, t, t); + printf ("%tn", tn); + printf ("%tf", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tF", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%te", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tE", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tg", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tG", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%ta", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tA", d); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tc", i); /* { dg-warning "length" "bad use of %t" } */ + printf ("%ts", s); /* { dg-warning "length" "bad use of %t" } */ + printf ("%tp", p); /* { dg-warning "length" "bad use of %t" } */ + printf ("%Le%LE%Lf%LF%Lg%LG%La%LA", ld, ld, ld, ld, ld, ld, ld, ld); + /* These next six are accepted by GCC as referring to long long, + but -pedantic correctly warns. + */ + printf ("%Ld", ll); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Li", ll); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lo", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lu", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lx", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%LX", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lc", i); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Ls", s); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Lp", p); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Ln", n); /* { dg-warning "length" "bad use of %L" } */ + /* Valid uses of each bare conversion. */ + printf ("%d%i%o%u%x%X%f%F%e%E%g%G%a%A%c%s%p%n%%", i, i, u, u, u, u, + d, d, d, d, d, d, d, d, i, s, p, n); + /* Uses of the - flag (valid on all non-%, non-n conversions). */ + printf ("%-d%-i%-o%-u%-x%-X%-f%-F%-e%-E%-g%-G%-a%-A%-c%-s%-p", i, i, + u, u, u, u, d, d, d, d, d, d, d, d, i, s, p); + printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */ + /* Uses of the + flag (valid on signed conversions only). */ + printf ("%+d%+i%+f%+F%+e%+E%+g%+G%+a%+A\n", i, i, d, d, d, d, d, d, d, d); + printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */ + /* Uses of the space flag (valid on signed conversions only, and ignored + with +). + */ + printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ + printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ + printf ("% d% i% f% F% e% E% g% G% a% A\n", i, i, d, d, d, d, d, d, d, d); + printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */ + /* Uses of the # flag. */ + printf ("%#o%#x%#X%#e%#E%#f%#F%#g%#G%#a%#A", u, u, u, d, d, d, d, + d, d, d, d); + printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */ + /* Uses of the 0 flag. */ + printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08F%08g%08G%08a%08A", i, i, + u, u, u, u, d, d, d, d, d, d, d, d); + printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */ + /* 0 flag ignored with precision for certain types, not others. */ + printf ("%08.5d", i); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5i", i); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5o", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5u", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5x", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5X", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5f%08.5F%08.5e%08.5E%08.5g%08.5G%08.5a%08.5A", + d, d, d, d, d, d, d, d); + /* 0 flag ignored with - flag. */ + printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08F", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08a", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08A", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + /* Various tests of bad argument types. Mostly covered in c90-printf-1.c; + here just test for pointer target sign with %hhn. (Probably allowed + by the standard, but a bad idea, so GCC should diagnose if what + is used is not signed char *.) + */ + printf ("%hhn", s); /* { dg-warning "format" "%hhn plain char" } */ + printf ("%hhn", us); /* { dg-warning "format" "%hhn unsigned char" } */ +}
c99-printf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: diag-1.c =================================================================== --- diag-1.c (nonexistent) +++ diag-1.c (revision 154) @@ -0,0 +1,18 @@ +/* Test for format diagnostics. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (double d) +{ + /* This should get a message referring to `hh', not to `H'. */ + 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', not to + 'unsigned int' or similar. */ + printf ("%zu", d); /* { dg-warning "size_t" "size_t format warning" } */ +}
diag-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: nonlit-2.c =================================================================== --- nonlit-2.c (nonexistent) +++ nonlit-2.c (revision 154) @@ -0,0 +1,13 @@ +/* Test for warnings for non-string-literal formats. Test with -Wformat=2. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat=2" } */ + +#include "format.h" + +void +foo (char *s, size_t i) +{ + printf ((const char *)i, i); /* { dg-warning "argument types" "non-literal" } */ + printf (s, i); /* { dg-warning "argument types" "non-literal" } */ +}
nonlit-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-printf-3.c =================================================================== --- c99-printf-3.c (nonexistent) +++ c99-printf-3.c (revision 154) @@ -0,0 +1,39 @@ +/* Test for printf formats. Test that the C99 functions get their default + attributes in strict C99 mode, but the gettext functions do not. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3, + va_list v4, va_list v5, va_list v6, va_list v7) +{ + fprintf (stdout, "%d", i); + fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ + printf ("%d", i); + printf ("%ld", i); /* { dg-warning "format" "printf" } */ + /* The "unlocked" functions shouldn't warn in c99 mode. */ + fprintf_unlocked (stdout, "%ld", i); /* { dg-bogus "format" "fprintf_unlocked" } */ + printf_unlocked ("%ld", i); /* { dg-bogus "format" "printf_unlocked" } */ + sprintf (s, "%d", i); + sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ + snprintf (s, n, "%d", i); + snprintf (s, n, "%ld", i); /* { dg-warning "format" "snprintf" } */ + vfprintf (stdout, "%d", v0); + vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */ + vprintf ("%d", v0); + vprintf ("%Y", v1); /* { dg-warning "format" "vprintf" } */ + vsprintf (s, "%d", v0); + vsprintf (s, "%Y", v1); /* { dg-warning "format" "vsprintf" } */ + vsnprintf (s, n, "%d", v0); + vsnprintf (s, n, "%Y", v1); /* { dg-warning "format" "vsnprintf" } */ + printf (gettext ("%d"), i); + printf (gettext ("%ld"), i); + printf (dgettext ("", "%d"), i); + printf (dgettext ("", "%ld"), i); + printf (dcgettext ("", "%d", 0), i); + printf (dcgettext ("", "%ld", 0), i); +}
c99-printf-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: z-1.c =================================================================== --- z-1.c (nonexistent) +++ z-1.c (revision 154) @@ -0,0 +1,28 @@ +/* Test for bugs with %z and %Z formats. See PRs c/89, c/156, c/376. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +size_t +foo (void) +{ + size_t t; + scanf ("%zu", &t); /* { dg-bogus "length|format" "bogus scanf warning" } */ + return t; +} + +void +bar (size_t t) +{ + printf ("%zu\n", t); /* { dg-bogus "format" "bogus printf warning" } */ +} + +/* The %Z printf format is an old GNU libc extension to do the same thing. */ + +void +baz (size_t t) +{ + printf ("%Zu\n", t); /* { dg-bogus "format" "bogus printf warning" } */ +}
z-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: asm_fprintf-2.c =================================================================== --- asm_fprintf-2.c (nonexistent) +++ asm_fprintf-2.c (revision 154) @@ -0,0 +1,9 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", not used at all, asm_fprintf format. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */
asm_fprintf-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_gfc-1.c =================================================================== --- gcc_gfc-1.c (nonexistent) +++ gcc_gfc-1.c (revision 154) @@ -0,0 +1,30 @@ +/* Test for gcc_gfc formats. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +/* Magic identifier must be set before the attribute is used. */ +typedef struct locus locus; + +extern int gfc_warn (const char *, ...) __attribute__ ((__format__ (__gcc_gfc__, 1, 2))) __attribute__ ((__nonnull__)); + +void +foo (int i, char *s, long int l, llong ll, locus *loc) +{ + /* Acceptable C90 specifiers, flags and modifiers. */ + gfc_warn ("%%"); + gfc_warn ("%d%i%c%s%%", i, i, i, s); + + /* Extensions provided in gfc_warn. */ + gfc_warn ("%C"); + gfc_warn ("%L", loc); + + /* Various tests of bad argument types. */ + gfc_warn ("%d", l); /* { dg-warning "format" "bad argument types" } */ + gfc_warn ("%d", ll); /* { dg-warning "format" "bad argument types" } */ + gfc_warn ("%s", &i); /* { dg-warning "format" "bad argument types" } */ + gfc_warn ("%L", &i); /* { dg-warning "format" "bad argument types" } */ + gfc_warn ("%C", i); /* { dg-warning "format" "too many arguments" } */ +}
gcc_gfc-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: asm_fprintf-4.c =================================================================== --- asm_fprintf-4.c (nonexistent) +++ asm_fprintf-4.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", not a type, asm_fprintf. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +int __gcc_host_wide_int__; +void bar (const char *, ...) __attribute__ ((__format__ (__asm_fprintf__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */
asm_fprintf-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: multattr-1.c =================================================================== --- multattr-1.c (nonexistent) +++ multattr-1.c (revision 154) @@ -0,0 +1,50 @@ +/* Test for multiple format attributes. Test for printf and scanf attributes + together. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +/* If we specify multiple attributes for a single function, they should + all apply. This should apply whether they are on the same declaration + or on different declarations. */ + +extern void my_vprintf_scanf (const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))) + __attribute__((__format__(__scanf__, 3, 4))); + +extern void my_vprintf_scanf2 (const char *, va_list, const char *, ...) + __attribute__((__format__(__scanf__, 3, 4))) + __attribute__((__format__(__printf__, 1, 0))); + +extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))); +extern void my_vprintf_scanf3 (const char *, va_list, const char *, ...) + __attribute__((__format__(__scanf__, 3, 4))); + +extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...) + __attribute__((__format__(__scanf__, 3, 4))); +extern void my_vprintf_scanf4 (const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))); + +void +foo (va_list ap, int *ip, long *lp) +{ + my_vprintf_scanf ("%d", ap, "%d", ip); + my_vprintf_scanf ("%d", ap, "%ld", lp); + my_vprintf_scanf ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ + my_vprintf_scanf2 ("%d", ap, "%d", ip); + my_vprintf_scanf2 ("%d", ap, "%ld", lp); + my_vprintf_scanf2 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf2 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ + my_vprintf_scanf3 ("%d", ap, "%d", ip); + my_vprintf_scanf3 ("%d", ap, "%ld", lp); + my_vprintf_scanf3 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf3 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ + my_vprintf_scanf4 ("%d", ap, "%d", ip); + my_vprintf_scanf4 ("%d", ap, "%ld", lp); + my_vprintf_scanf4 ("%", ap, "%d", ip); /* { dg-warning "format" "printf" } */ + my_vprintf_scanf4 ("%d", ap, "%ld", ip); /* { dg-warning "format" "scanf" } */ +}
multattr-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-2.c =================================================================== --- miss-2.c (nonexistent) +++ miss-2.c (revision 154) @@ -0,0 +1,16 @@ +/* Test for warnings for missing format attributes. Don't warn if no + relevant parameters for a format attribute; see c/1017. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wmissing-format-attribute" } */ + +#include "format.h" + +void +foo (int i, ...) +{ + va_list ap; + va_start (ap, i); + vprintf ("Foo %s bar %s", ap); /* { dg-bogus "candidate" "bogus printf attribute warning" } */ + va_end (ap); +}
miss-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: multattr-3.c =================================================================== --- multattr-3.c (nonexistent) +++ multattr-3.c (revision 154) @@ -0,0 +1,28 @@ +/* Test for multiple format_arg attributes. Test for both branches + getting checked. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +extern char *ngettext (const char *, const char *, unsigned long int) + __attribute__((__format_arg__(1))) __attribute__((__format_arg__(2))); + +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" "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" "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" } */ +}
multattr-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: array-1.c =================================================================== --- array-1.c (nonexistent) +++ array-1.c (revision 154) @@ -0,0 +1,39 @@ +/* Test for format checking of constant arrays. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat=2" } */ + +#include "format.h" + +const char a1[] = "foo"; +const char a2[] = "foo%d"; +const char b[3] = "foo"; +static const char c1[] = "foo"; +static const char c2[] = "foo%d"; +char d[] = "foo"; +volatile const char e[] = "foo"; + +void +foo (int i, long l) +{ + const char p1[] = "bar"; + const char p2[] = "bar%d"; + static const char q1[] = "bar"; + static const char q2[] = "bar%d"; + printf (a1); + printf (a2, i); + printf (a2, l); /* { dg-warning "format" "wrong type with array" } */ + printf (b); /* { dg-warning "unterminated" "unterminated array" } */ + printf (c1); + printf (c2, i); + printf (c2, l); /* { dg-warning "format" "wrong type with array" } */ + printf (p1); + printf (p2, i); + printf (p2, l); /* { dg-warning "format" "wrong type with array" } */ + printf (q1); + printf (q2, i); + printf (q2, l); /* { dg-warning "format" "wrong type with array" } */ + /* Volatile or non-constant arrays must not be checked. */ + printf (d); /* { dg-warning "not a string literal" "non-const" } */ + printf ((const char *)e); /* { dg-warning "not a string literal" "volatile" } */ +}
array-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-4.c =================================================================== --- miss-4.c (nonexistent) +++ miss-4.c (revision 154) @@ -0,0 +1,32 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { 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; +}
miss-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: errmk-1.c =================================================================== --- errmk-1.c (nonexistent) +++ errmk-1.c (revision 154) @@ -0,0 +1,12 @@ +/* Test for format checking not giving tree checking errors. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +void +foo (int t) +{ + printf ("%*d", u, t); /* { dg-error "undeclared|function" "u undeclared error" } */ +}
errmk-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: miss-6.c =================================================================== --- miss-6.c (nonexistent) +++ miss-6.c (revision 154) @@ -0,0 +1,31 @@ +/* Test warnings for missing format attributes on function pointers. */ +/* Origin: Kaveh Ghazi */ +/* { 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); +}
miss-6.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-2.c =================================================================== --- gcc_diag-2.c (nonexistent) +++ gcc_diag-2.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test "tree", not + defined. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +void foo (int tree); +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2)));
gcc_diag-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: sentinel-1.c =================================================================== --- sentinel-1.c (nonexistent) +++ sentinel-1.c (revision 154) @@ -0,0 +1,73 @@ +/* Test for attribute sentinel. */ +/* Origin: Kaveh Ghazi */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include /* For NULL, which must be (ptr)0. */ + +extern int execl (const char *, const char *, ...); +extern int execlp (const char *, const char *, ...); +extern int execle (const char *, const char *, ...); +extern char *envp[]; + +#define ATTR __attribute__ ((__sentinel__)) + +extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */ + +extern void foo1 (const char *, ...) ATTR; +extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */ +extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */ +extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */ +extern void foo5 (const char *, ...) __attribute__ ((__sentinel__(1))); +extern void foo6 (const char *, ...) __attribute__ ((__sentinel__(5))); +extern void foo7 (const char *, ...) __attribute__ ((__sentinel__(0))); +extern void foo8 (const char *, ...) __attribute__ ((__sentinel__("a"))); /* { dg-warning "not an integer constant" "sentinel" } */ +extern void foo9 (const char *, ...) __attribute__ ((__sentinel__(-1))); /* { dg-warning "less than zero" "sentinel" } */ +extern void foo10 (const char *, ...) __attribute__ ((__sentinel__(1,3))); /* { dg-error "wrong number of arguments" "sentinel" } */ + +extern void bar(void) +{ + foo1 (); /* { dg-error "not enough|too few arguments" "sentinel" } */ + foo1 (NULL); /* { dg-warning "not enough" "sentinel" } */ + foo1 ("a"); /* { dg-warning "not enough" "sentinel" } */ + foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */ + foo1 ("a", 0); /* { dg-warning "missing sentinel" "sentinel" } */ + foo1 ("a", (void*)1); /* { dg-warning "missing sentinel" "sentinel" } */ + foo1 ("a", NULL, 1); /* { dg-warning "missing sentinel" "sentinel" } */ + foo1 ("a", NULL); + + foo5 (NULL); /* { dg-warning "not enough" "sentinel" } */ + foo5 (NULL, 1); /* { dg-warning "not enough" "sentinel" } */ + foo5 ("a", NULL); /* { dg-warning "not enough" "sentinel" } */ + foo5 ("a", NULL, 1); + foo5 ("a", 1, 2, 3, NULL); /* { dg-warning "missing sentinel" "sentinel" } */ + foo5 ("a", 1, 2, NULL, 3); + foo5 ("a", 1, NULL, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */ + foo5 ("a", NULL, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */ + foo5 ("a", 0, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */ + + foo6 ("a", 1, NULL); /* { dg-warning "not enough" "sentinel" } */ + foo6 ("a", 1, NULL, 2); /* { dg-warning "not enough" "sentinel" } */ + foo6 ("a", 1, NULL, 2, 3); /* { dg-warning "not enough" "sentinel" } */ + foo6 ("a", NULL, 1, 2, 3); /* { dg-warning "not enough" "sentinel" } */ + foo6 ("a", NULL, 1, 2, 3, 4); /* { dg-warning "not enough" "sentinel" } */ + foo6 (NULL, 1, 2, 3, 4, 5); /* { dg-warning "not enough" "sentinel" } */ + foo6 ("a", NULL, 1, 2, 3, 4, 5); + foo6 ("a", 0, NULL, 1, 2, 3, 4, 5); + foo6 ("a", 0, 1, 2, 3, 4, 5); /* { dg-warning "missing sentinel" "sentinel" } */ + foo6 ("a", NULL, 1, 2, 3, 4, 5, 6); /* { dg-warning "missing sentinel" "sentinel" } */ + + foo7 ("a", 1, 2, 3, NULL); + + execl ("/bin/ls", "/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */ + execl ("/bin/ls", "/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */ + execl ("/bin/ls", "/bin/ls", "-aFC", NULL); + + execlp ("ls", "ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */ + execlp ("ls", "ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */ + execlp ("ls", "ls", "-aFC", NULL); + + execle ("ls", "ls", "-aFC", ".", envp); /* { dg-warning "missing sentinel" "sentinel" } */ + execle ("ls", "ls", "-aFC", ".", 0, envp); /* { dg-warning "missing sentinel" "sentinel" } */ + execle ("ls", "ls", "-aFC", ".", NULL, envp); +}
sentinel-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-4.c =================================================================== --- gcc_diag-4.c (nonexistent) +++ gcc_diag-4.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test "tree", not + a pointer type. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +typedef int tree; +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'tree' is not defined as a pointer type" } */
gcc_diag-4.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-6.c =================================================================== --- gcc_diag-6.c (nonexistent) +++ gcc_diag-6.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "location_t", not a type. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +int location_t; +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: 'location_t' is not defined as a type" } */
gcc_diag-6.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-strftime-1.c =================================================================== --- c90-strftime-1.c (nonexistent) +++ c90-strftime-1.c (revision 154) @@ -0,0 +1,19 @@ +/* Test for strftime formats. Formats using C90 features. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wformat-y2k" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175). */ + /* Formats which are Y2K-compliant (no 2-digit years). */ + strftime (s, m, "%a%A%b%B%d%H%I%j%m%M%p%S%U%w%W%X%Y%Z%%", tp); + /* Formats with 2-digit years. */ + strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */ + /* Formats with 2-digit years in some locales. */ + strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */ + strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */ +}
c90-strftime-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: gcc_diag-8.c =================================================================== --- gcc_diag-8.c (nonexistent) +++ gcc_diag-8.c (revision 154) @@ -0,0 +1,10 @@ +/* Test for ICE handling internal formats: bug 20740. The code did + not check that, if the required typedef names had been used as + identifiers, they were defined to suitable types. Test + "__gcc_host_wide_int__", not a type. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +int __gcc_host_wide_int__; +void bar (const char *, ...) __attribute__ ((__format__ (__gcc_diag__, 1, 2))); /* { dg-error "error: '__gcc_host_wide_int__' is not defined as a type" } */
gcc_diag-8.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-printf-1.c =================================================================== --- c90-printf-1.c (nonexistent) +++ c90-printf-1.c (revision 154) @@ -0,0 +1,237 @@ +/* Test for printf formats. Formats using C90 features, including cases + where C90 specifies some aspect of the format to be ignored or where + the behavior is undefined. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, + int *n, short int *hn, long int l, unsigned long int ul, + long int *ln, long double ld, wint_t lc, wchar_t *ls, llong ll, + ullong ull, unsigned int *un, const int *cn, signed char *ss, + unsigned char *us, const signed char *css, unsigned int u1, + unsigned int u2) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134). */ + /* Basic sanity checks for the different components of a format. */ + printf ("%d\n", i); + printf ("%+d\n", i); + printf ("%3d\n", i); + printf ("%-3d\n", i); + printf ("%.7d\n", i); + printf ("%+9.4d\n", i); + printf ("%.3ld\n", l); + printf ("%*d\n", i1, i); + printf ("%.*d\n", i2, i); + printf ("%*.*ld\n", i1, i2, l); + printf ("%d %lu\n", i, ul); + /* GCC has objected to the next one in the past, but it is a valid way + of specifying zero precision. + */ + printf ("%.e\n", d); /* { dg-bogus "precision" "bogus precision warning" } */ + /* Bogus use of width. */ + printf ("%5n\n", n); /* { dg-warning "width" "width with %n" } */ + /* Erroneous, ignored or pointless constructs with precision. */ + /* Whether negative values for precision may be included in the format + string is not entirely clear; presume not, following Clive Feather's + proposed resolution to DR#220 against C99. In any case, such a + construct should be warned about. + */ + printf ("%.-5d\n", i); /* { dg-warning "format|precision" "negative precision warning" } */ + printf ("%.-*d\n", i); /* { dg-warning "format" "broken %.-*d format" } */ + printf ("%.3c\n", i); /* { dg-warning "precision" "precision with %c" } */ + printf ("%.3p\n", p); /* { dg-warning "precision" "precision with %p" } */ + printf ("%.3n\n", n); /* { dg-warning "precision" "precision with %n" } */ + /* Valid and invalid %% constructions. Some of the warning messages + are non-optimal, but they do detect the errorneous nature of the + format string. + */ + printf ("%%"); + printf ("%.3%"); /* { dg-warning "format" "bogus %%" } */ + printf ("%-%"); /* { dg-warning "format" "bogus %%" } */ + printf ("%-%\n"); /* { dg-warning "format" "bogus %%" } */ + printf ("%5%\n"); /* { dg-warning "format" "bogus %%" } */ + printf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */ + /* Valid and invalid %h, %l, %L constructions. */ + printf ("%hd", i); + printf ("%hi", i); + /* Strictly, these parameters should be int or unsigned int according to + what unsigned short promotes to. However, GCC ignores sign + differences in format checking here, and this is relied on to get the + correct checking without print_char_table needing to know whether + int and short are the same size. + */ + printf ("%ho%hu%hx%hX", u, u, u, u); + printf ("%hn", hn); + printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hc", i); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hs", s); /* { dg-warning "length" "bad use of %h" } */ + printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */ + printf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */ + printf ("%h."); /* { dg-warning "conversion" "bogus %h." } */ + printf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul); + printf ("%ln", ln); + printf ("%lf", d); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%le", d); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%lE", d); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%lg", d); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%lG", d); /* { dg-warning "length|C" "bad use of %l" } */ + printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */ + /* These next two were added in C94, but should be objected to in C90. + For the first one, GCC has wanted wchar_t instead of the correct C94 + and C99 wint_t. + */ + printf ("%lc", lc); /* { dg-warning "length|C" "C90 bad use of %l" } */ + printf ("%ls", ls); /* { dg-warning "length|C" "C90 bad use of %l" } */ + /* These uses of %L are legitimate, though GCC has wrongly warned for + them in the past. + */ + printf ("%Le%LE%Lf%Lg%LG", ld, ld, ld, ld, ld); + /* These next six are accepted by GCC as referring to long long, + but -pedantic correctly warns. + */ + printf ("%Ld", ll); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Li", ll); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lo", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lu", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lx", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%LX", ull); /* { dg-warning "does not support" "bad use of %L" } */ + printf ("%Lc", i); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Ls", s); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Lp", p); /* { dg-warning "length" "bad use of %L" } */ + printf ("%Ln", n); /* { dg-warning "length" "bad use of %L" } */ + /* Valid uses of each bare conversion. */ + printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u, d, d, d, d, d, + i, s, p, n); + /* Uses of the - flag (valid on all non-%, non-n conversions). */ + printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i, u, u, u, u, + d, d, d, d, d, i, s, p); + printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */ + /* Uses of the + flag (valid on signed conversions only). */ + printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d); + printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */ + printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */ + /* Uses of the space flag (valid on signed conversions only, and ignored + with +). + */ + printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ + printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ + printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d); + printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */ + printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */ + /* Uses of the # flag. */ + printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d, d, d); + printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */ + printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */ + /* Uses of the 0 flag. */ + printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i, u, u, u, u, + d, d, d, d, d); + printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */ + printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */ + /* 0 flag ignored with precision for certain types, not others. */ + printf ("%08.5d", i); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5i", i); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5o", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5u", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5x", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5X", u); /* { dg-warning "ignored" "0 flag ignored with precision" } */ + printf ("%08.5f%08.5e%08.5E%08.5g%08.5G", d, d, d, d, d); + /* 0 flag ignored with - flag. */ + printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ + /* Various tests of bad argument types. */ + printf ("%d", l); /* { dg-warning "format" "bad argument types" } */ + printf ("%*.*d", l, i2, i); /* { dg-warning "field" "bad * argument types" } */ + printf ("%*.*d", i1, l, i); /* { dg-warning "field" "bad * argument types" } */ + printf ("%ld", i); /* { dg-warning "format" "bad argument types" } */ + printf ("%s", n); /* { dg-warning "format" "bad argument types" } */ + printf ("%p", i); /* { dg-warning "format" "bad argument types" } */ + printf ("%n", p); /* { dg-warning "format" "bad argument types" } */ + /* With -pedantic, we want some further checks for pointer targets: + %p should allow only pointers to void (possibly qualified) and + to character types (possibly qualified), but not function pointers + or pointers to other types. (Whether, in fact, character types are + allowed here is unclear; see thread on comp.std.c, July 2000 for + discussion of the requirements of rules on identical representation, + and of the application of the as if rule with the new va_arg + allowances in C99 to printf.) Likewise, we should warn if + pointer targets differ in signedness, except in some circumstances + for character pointers. (In C99 we should consider warning for + char * or unsigned char * being passed to %hhn, even if strictly + legitimate by the standard.) + */ + printf ("%p", foo); /* { dg-warning "format" "bad argument types" } */ + printf ("%n", un); /* { dg-warning "format" "bad argument types" } */ + printf ("%p", n); /* { dg-warning "format" "bad argument types" } */ + /* Allow character pointers with %p. */ + printf ("%p%p%p%p", s, ss, us, css); + /* %s allows any character type. */ + printf ("%s%s%s%s", s, ss, us, css); + /* Warning for void * arguments for %s is GCC's historical behavior, + and seems useful to keep, even if some standard versions might be + read to permit it. + */ + printf ("%s", p); /* { dg-warning "format" "bad argument types" } */ + /* The historical behavior is to allow signed / unsigned types + interchangably as arguments. For values representable in both types, + such usage may be correct. For now preserve the behavior of GCC + in such cases. + */ + printf ("%d", u); + /* Also allow the same for width and precision arguments. In the past, + GCC has been inconsistent and allowed unsigned for width but not + precision. + */ + printf ("%*.*d", u1, u2, i); + /* Wrong number of arguments. */ + printf ("%d%d", i); /* { dg-warning "arguments" "wrong number of args" } */ + printf ("%d", i, i); /* { dg-warning "arguments" "wrong number of args" } */ + /* Miscellaneous bogus constructions. */ + printf (""); /* { dg-warning "zero-length" "warning for empty format" } */ + printf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ + printf ("%d\0", i); /* { dg-warning "embedded" "warning for embedded NUL" } */ + printf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ + printf (NULL); /* { dg-warning "null" "null format string warning" } */ + printf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ + printf ("%++d", i); /* { dg-warning "repeated" "repeated flag warning" } */ + printf ("%n", cn); /* { dg-warning "constant" "%n with const" } */ + printf ((const char *)L"foo"); /* { dg-warning "wide" "wide string" } */ + printf ("%n", (int *)0); /* { dg-warning "null" "%n with NULL" } */ + printf ("%s", (char *)0); /* { dg-warning "null" "%s with NULL" } */ +}
c90-printf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-printf-3.c =================================================================== --- c90-printf-3.c (nonexistent) +++ c90-printf-3.c (revision 154) @@ -0,0 +1,42 @@ +/* Test for printf formats. Test that the C90 functions get their default + attributes in strict C90 mode, but the C99 and gettext functions + do not. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int i, char *s, size_t n, va_list v0, va_list v1, va_list v2, va_list v3, + va_list v4, va_list v5, va_list v6, va_list v7, va_list v8) +{ + fprintf (stdout, "%d", i); + fprintf (stdout, "%ld", i); /* { dg-warning "format" "fprintf" } */ + printf ("%d", i); + printf ("%ld", i); /* { dg-warning "format" "printf" } */ + /* The "unlocked" functions shouldn't warn in c90 mode. */ + fprintf_unlocked (stdout, "%ld", i); /* { dg-bogus "format" "fprintf_unlocked" } */ + printf_unlocked ("%ld", i); /* { dg-bogus "format" "printf_unlocked" } */ + sprintf (s, "%d", i); + sprintf (s, "%ld", i); /* { dg-warning "format" "sprintf" } */ + vfprintf (stdout, "%d", v0); + vfprintf (stdout, "%Y", v1); /* { dg-warning "format" "vfprintf" } */ + vprintf ("%d", v2); + vprintf ("%Y", v3); /* { dg-warning "format" "vprintf" } */ + /* The following used to give a bogus warning. */ + vprintf ("%*.*d", v8); + vsprintf (s, "%d", v4); + vsprintf (s, "%Y", v5); /* { dg-warning "format" "vsprintf" } */ + snprintf (s, n, "%d", i); + snprintf (s, n, "%ld", i); + vsnprintf (s, n, "%d", v6); + vsnprintf (s, n, "%Y", v7); + printf (gettext ("%d"), i); + printf (gettext ("%ld"), i); + printf (dgettext ("", "%d"), i); + printf (dgettext ("", "%ld"), i); + printf (dcgettext ("", "%d", 0), i); + printf (dcgettext ("", "%ld", 0), i); +}
c90-printf-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c94-printf-1.c =================================================================== --- c94-printf-1.c (nonexistent) +++ c94-printf-1.c (revision 154) @@ -0,0 +1,18 @@ +/* Test for printf formats. Changes in C94 to C90. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (wint_t lc, wchar_t *ls) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.1 (pages 131-134), + as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 4-5). + We do not repeat here all the C90 format checks, but just verify + that %ls and %lc are accepted without warning. + */ + printf ("%lc", lc); + printf ("%ls", ls); +}
c94-printf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: ext-1.c =================================================================== --- ext-1.c (nonexistent) +++ ext-1.c (revision 154) @@ -0,0 +1,126 @@ +/* Test for format extensions beyond the C standard and X/Open standard. + Test for printf formats. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (quad_t q, u_quad_t uq, quad_t *qn, size_t z, size_t *zn, long long int ll, + unsigned long long int ull, int i, unsigned int u, double d, + char *s, void *p, wchar_t *ls, wint_t lc, int *n, long int l) +{ + /* As an extension, GCC allows the BSD length "q" for integer formats. + This is largely obsoleted in C99 by %j, %ll and PRId64. + */ + printf ("%qd%qi%qo%qu%qx%qX%qn", q, q, uq, uq, uq, uq, qn); + printf ("%qf", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qF", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qe", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qE", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qg", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qG", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qa", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qA", d); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qc", i); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qs", s); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qp", p); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qC", lc); /* { dg-warning "length" "bad use of %q" } */ + printf ("%qS", ls); /* { dg-warning "length" "bad use of %q" } */ + /* With a bad length GCC wants some argument, any argument, + to devour with the format conversion, as a synchronisation heuristic. + This may get improved later. + */ + printf ("%qm", i); /* { dg-warning "length" "bad use of %q" } */ + /* As an extension, GCC allows the length "Z" as a synonym for "z". + This was an extension predating C99 which should now be considered + deprecated; use the standard "z" instead. + */ + printf ("%Zd%Zi%Zo%Zu%Zx%ZX", z, z, z, z, z, z); + printf ("%Zn", zn); + printf ("%Zf", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZF", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Ze", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZE", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Zg", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZG", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Za", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZA", d); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Zc", i); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Zs", s); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Zp", p); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZC", lc); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%ZS", ls); /* { dg-warning "length" "bad use of %Z" } */ + printf ("%Zm", i); /* { dg-warning "length" "bad use of %Z" } */ + /* As an extension, GCC allows the length "L" on integer formats + (but not %n) as a synonym for "ll". + This should be considered deprecated. + */ + printf ("%Ld%Li%Lo%Lu%Lx%LX", ll, ll, ull, ull, ull, ull); + /* As an extension, derived from syslog, GCC allows the conversion + specifier "m" for formatting strerror(errno). This may be used + with width, precision and the "-" flag, the same as %s. + */ + printf ("%m%3m%.4m%5.6m"); + printf ("%*m", i); + printf ("%.*m", i); + printf ("%*.*m", i, i); + printf ("%3.*m", i); + printf ("%*.4m", i); + printf ("%-m"); + printf ("%+m"); /* { dg-warning "flag" "bad %+m" } */ + printf ("% m"); /* { dg-warning "flag" "bad % m" } */ + printf ("%#m"); /* { dg-warning "flag" "bad %#m" } */ + printf ("%0m"); /* { dg-warning "flag" "bad %0m" } */ + printf ("%'m"); /* { dg-warning "flag" "bad %'m" } */ + printf ("%hm", i); /* { dg-warning "length" "bad %hm" } */ + printf ("%hhm", i); /* { dg-warning "length" "bad %hhm" } */ + printf ("%lm", i); /* { dg-warning "length" "bad %lm" } */ + printf ("%llm", i); /* { dg-warning "length" "bad %llm" } */ + printf ("%jm", i); /* { dg-warning "length" "bad %jm" } */ + printf ("%zm", i); /* { dg-warning "length" "bad %zm" } */ + printf ("%tm", i); /* { dg-warning "length" "bad %tm" } */ + printf ("%Lm", i); /* { dg-warning "length" "bad %Lm" } */ + printf ("%qm", i); /* { dg-warning "length" "bad %qm" } */ + printf ("%Zm", i); /* { dg-warning "length" "bad %Zm" } */ + /* It should be OK to mix %m formats with $ operand number formats. */ + printf ("%2$ld%m%1$d", i, l); + /* Likewise, %m formats with width and precision should not have an + operand number for the %m itself. + */ + printf ("%*2$.*1$m", i, i); + printf ("%1$*2$.*1$m", i, i); /* { dg-warning "no argument" "printf %1\$m" } */ + /* As an extension, glibc includes the "I" flag for decimal + formats, to output using the locale's digits (e.g. in Arabic). + In GCC, we require this to be in the standard place for flags, though + glibc allows it also after width or precision. + */ + printf ("%Id%Ii%Iu", i, i, u); + printf ("%Io", u); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%Ix", u); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%IX", u); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%In", n); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%If", d); + printf ("%IF", d); + printf ("%Ie", d); + printf ("%IE", d); + printf ("%Ig", d); + printf ("%IG", d); + printf ("%Ia", d); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%IA", d); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%Ic", i); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%Is", s); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%Ip", p); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%IC", lc); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%IS", ls); /* { dg-warning "flag" "bad use of I flag" } */ + printf ("%Im"); /* { dg-warning "flag" "bad use of I flag" } */ + + /* As an extension, GCC does format checking on "unlocked" + i.e. thread unsafe versions of these functions. */ + fprintf_unlocked (stdout, "%d", i); + fprintf_unlocked (stdout, "%ld", i); /* { dg-warning "format" "fprintf_unlocked" } */ + printf_unlocked ("%d", i); + printf_unlocked ("%ld", i); /* { dg-warning "format" "printf_unlocked" } */ +}
ext-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: opt-1.c =================================================================== --- opt-1.c (nonexistent) +++ opt-1.c (revision 154) @@ -0,0 +1,7 @@ +/* Test diagnostics for options used on their own without + -Wformat. -Wformat-extra-args. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat-extra-args" } */ + +/* { dg-warning "warning: -Wformat-extra-args ignored without -Wformat" "ignored" { target *-*-* } 0 } */
opt-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: ext-3.c =================================================================== --- ext-3.c (nonexistent) +++ ext-3.c (revision 154) @@ -0,0 +1,216 @@ +/* Test for format extensions beyond the C standard and X/Open standard. + Test for strftime formats. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wformat-y2k" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + /* GCC accepts the "-", "_" and "0" flags to control padding on numeric + formats. It also accepts width on these formats. + */ + /* Basic tests of parts on their own. */ + strftime (s, m, "%5C%-C%_C%0C", tp); + /* Correct usages. */ + strftime (s, m, "%-5C%_5C%05C%-5d%_5d%05d%-5e%_5e%05e%-5G%_5G%05G", tp); + strftime (s, m, "%-5H%_5H%05H%-5I%_5I%05I%-5j%_5j%05j%-5m%_5m%05m", tp); + strftime (s, m, "%-5M%_5M%05M%-5S%_5S%05S%-5u%_5u%05u%-5U%_5U%05U", tp); + strftime (s, m, "%-5V%_5V%05V%-5w%_5w%05w%-5W%_5W%05W%-5Y%_5Y%05Y", tp); + /* Correct usages with GNU extension conversion characters. */ + strftime (s, m, "%-5k%_5k%05k%-5l%_5l%05l%-20s%_20s%020s", tp); + /* Correct usages with Y2K problems. */ + strftime (s, m, "%-5g%_5g%05g%-5y%_5y%05y", tp); /* { dg-warning "only last 2" "2-digit year" } */ + /* Incorrect usages. */ + strftime (s, m, "%5a", tp); /* { dg-warning "width" "bad %a" } */ + strftime (s, m, "%-a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%_a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%0a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%5A", tp); /* { dg-warning "width" "bad %A" } */ + strftime (s, m, "%-A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%_A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%0A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%5b", tp); /* { dg-warning "width" "bad %b" } */ + strftime (s, m, "%-b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%_b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%0b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%5B", tp); /* { dg-warning "width" "bad %B" } */ + strftime (s, m, "%-B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%_B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%0B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%5F", tp); /* { dg-warning "width" "bad %F" } */ + strftime (s, m, "%-F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%_F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%0F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%5h", tp); /* { dg-warning "width" "bad %h" } */ + strftime (s, m, "%-h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%_h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%0h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%5n", tp); /* { dg-warning "width" "bad %n" } */ + strftime (s, m, "%-n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%_n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%0n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%5p", tp); /* { dg-warning "width" "bad %p" } */ + strftime (s, m, "%-p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%_p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%0p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%5r", tp); /* { dg-warning "width" "bad %r" } */ + strftime (s, m, "%-r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%_r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%0r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%5R", tp); /* { dg-warning "width" "bad %R" } */ + strftime (s, m, "%-R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%_R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%0R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%5t", tp); /* { dg-warning "width" "bad %t" } */ + strftime (s, m, "%-t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%_t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%0t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%5T", tp); /* { dg-warning "width" "bad %T" } */ + strftime (s, m, "%-T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%_T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%0T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%5X", tp); /* { dg-warning "width" "bad %X" } */ + strftime (s, m, "%-X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%_X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%0X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%5z", tp); /* { dg-warning "width" "bad %z" } */ + strftime (s, m, "%-z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%_z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%0z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%5Z", tp); /* { dg-warning "width" "bad %Z" } */ + strftime (s, m, "%-Z", tp); /* { dg-warning "flag" "bad %Z" } */ + strftime (s, m, "%_Z", tp); /* { dg-warning "flag" "bad %Z" } */ + strftime (s, m, "%0Z", tp); /* { dg-warning "flag" "bad %Z" } */ + /* Incorrect usages with Y2K problems. */ + strftime (s, m, "%5c", tp); /* { dg-warning "width" "bad %c" } */ + strftime (s, m, "%-c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%_c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%0c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%5D", tp); /* { dg-warning "width" "bad %D" } */ + strftime (s, m, "%-D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%_D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%0D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%5x", tp); /* { dg-warning "width" "bad %x" } */ + strftime (s, m, "%-x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%_x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%0x", tp); /* { dg-warning "flag" "bad %x" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 89 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 90 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 91 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 92 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 93 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 94 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 95 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 96 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 97 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 98 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 99 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 100 } */ + /* Incorrect usages with GNU extension conversion characters. */ + strftime (s, m, "%5P", tp); /* { dg-warning "width" "bad %P" } */ + strftime (s, m, "%-P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%_P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%0P", tp); /* { dg-warning "flag" "bad %P" } */ + /* The "^" and "#" flags control the case of the output. + ^ (uppercase) makes sense on aAbBhZ; # (change case) makes sense + on the same and on p. + */ + strftime (s, m, "%^a%#a%^A%#A%^b%#b%^B%#B%^h%#h%^Z%#Z%#p", tp); + /* Bad usages. */ + strftime (s, m, "%^C", tp); /* { dg-warning "flag" "bad %C" } */ + strftime (s, m, "%#C", tp); /* { dg-warning "flag" "bad %C" } */ + strftime (s, m, "%^d", tp); /* { dg-warning "flag" "bad %d" } */ + strftime (s, m, "%#d", tp); /* { dg-warning "flag" "bad %d" } */ + strftime (s, m, "%^e", tp); /* { dg-warning "flag" "bad %e" } */ + strftime (s, m, "%#e", tp); /* { dg-warning "flag" "bad %e" } */ + strftime (s, m, "%^F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%#F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%^G", tp); /* { dg-warning "flag" "bad %G" } */ + strftime (s, m, "%#G", tp); /* { dg-warning "flag" "bad %G" } */ + strftime (s, m, "%^H", tp); /* { dg-warning "flag" "bad %H" } */ + strftime (s, m, "%#H", tp); /* { dg-warning "flag" "bad %H" } */ + strftime (s, m, "%^I", tp); /* { dg-warning "flag" "bad %I" } */ + strftime (s, m, "%#I", tp); /* { dg-warning "flag" "bad %I" } */ + strftime (s, m, "%^j", tp); /* { dg-warning "flag" "bad %j" } */ + strftime (s, m, "%#j", tp); /* { dg-warning "flag" "bad %j" } */ + strftime (s, m, "%^m", tp); /* { dg-warning "flag" "bad %m" } */ + strftime (s, m, "%#m", tp); /* { dg-warning "flag" "bad %m" } */ + strftime (s, m, "%^M", tp); /* { dg-warning "flag" "bad %M" } */ + strftime (s, m, "%#M", tp); /* { dg-warning "flag" "bad %M" } */ + strftime (s, m, "%^n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%#n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%^p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%^r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%#r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%^R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%#R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%^S", tp); /* { dg-warning "flag" "bad %S" } */ + strftime (s, m, "%#S", tp); /* { dg-warning "flag" "bad %S" } */ + strftime (s, m, "%^t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%#t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%^T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%#T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%^u", tp); /* { dg-warning "flag" "bad %u" } */ + strftime (s, m, "%#u", tp); /* { dg-warning "flag" "bad %u" } */ + strftime (s, m, "%^U", tp); /* { dg-warning "flag" "bad %U" } */ + strftime (s, m, "%#U", tp); /* { dg-warning "flag" "bad %U" } */ + strftime (s, m, "%^V", tp); /* { dg-warning "flag" "bad %V" } */ + strftime (s, m, "%#V", tp); /* { dg-warning "flag" "bad %V" } */ + strftime (s, m, "%^w", tp); /* { dg-warning "flag" "bad %w" } */ + strftime (s, m, "%#w", tp); /* { dg-warning "flag" "bad %w" } */ + strftime (s, m, "%^W", tp); /* { dg-warning "flag" "bad %W" } */ + strftime (s, m, "%#W", tp); /* { dg-warning "flag" "bad %W" } */ + strftime (s, m, "%^X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%#X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%^Y", tp); /* { dg-warning "flag" "bad %Y" } */ + strftime (s, m, "%#Y", tp); /* { dg-warning "flag" "bad %Y" } */ + strftime (s, m, "%^z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%#z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%^P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%#P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%^k", tp); /* { dg-warning "flag" "bad %k" } */ + strftime (s, m, "%#k", tp); /* { dg-warning "flag" "bad %k" } */ + strftime (s, m, "%^l", tp); /* { dg-warning "flag" "bad %l" } */ + strftime (s, m, "%#l", tp); /* { dg-warning "flag" "bad %l" } */ + strftime (s, m, "%^s", tp); /* { dg-warning "flag" "bad %s" } */ + strftime (s, m, "%#s", tp); /* { dg-warning "flag" "bad %s" } */ + /* Bad usages with Y2K problems. */ + strftime (s, m, "%^c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%#c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%^D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%#D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%^g", tp); /* { dg-warning "flag" "bad %g" } */ + strftime (s, m, "%#g", tp); /* { dg-warning "flag" "bad %g" } */ + strftime (s, m, "%^x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%#x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%^y", tp); /* { dg-warning "flag" "bad %y" } */ + strftime (s, m, "%#y", tp); /* { dg-warning "flag" "bad %y" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 182 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 183 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 184 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 185 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 186 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 187 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 188 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 189 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 190 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 191 } */ + /* GCC also accepts the glibc format extensions %P, %k, %l, %s. */ + strftime (s, m, "%P%k%l%s", tp); + /* GCC also accepts the glibc extension of the "O" modifier on some + more formats. The cases where it is rejected altogether are + covered in c99-strftime-1.c, except for the extension %P. + */ + strftime (s, m, "%OC%Og%OG%Oj%OY%Oz%Ok%Ol%Os", tp); /* { dg-warning "only last 2" "2-digit year" } */ + strftime (s, m, "%OP", tp); /* { dg-warning "flag|modifier" "bad %OP" } */ + /* The "-", "_" and "0" flags are mutually exclusive. */ + strftime (s, m, "%-_5C", tp); /* { dg-warning "flag" "bad %-_" } */ + strftime (s, m, "%-05C", tp); /* { dg-warning "flag" "bad %-0" } */ + strftime (s, m, "%_05C", tp); /* { dg-warning "flag" "bad %_0" } */ + /* The "#" and "^" flags are mutually exclusive. */ + strftime (s, m, "%^#a", tp); /* { dg-warning "flag" "bad %^#" } */ +}
ext-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: opt-3.c =================================================================== --- opt-3.c (nonexistent) +++ opt-3.c (revision 154) @@ -0,0 +1,7 @@ +/* Test diagnostics for options used on their own without + -Wformat. -Wformat-security. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat-security" } */ + +/* { dg-warning "warning: -Wformat-security ignored without -Wformat" "ignored" { target *-*-* } 0 } */
opt-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: format.exp =================================================================== --- format.exp (nonexistent) +++ format.exp (revision 154) @@ -0,0 +1,63 @@ +# Copyright (C) 1997, 2000, 2001, 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Don't run this directory with any default CFLAGS, but run tests with +# and without -DWIDE. + +if [info exists TORTURE_OPTIONS] { + set old_TORTURE_OPTIONS $TORTURE_OPTIONS +} elseif [info exists old_TORTURE_OPTIONS] { + unset old_TORTURE_OPTIONS +} +if [info exists torture_with_loops] { + set old_torture_with_loops $torture_with_loops +} elseif [info exists old_torture_with_loops] { + unset old_torture_with_loops +} +if [info exists torture_without_loops] { + set old_torture_without_loops $torture_without_loops +} elseif [info exists old_torture_without_loops] { + unset old_torture_without_loops +} +set TORTURE_OPTIONS [list { } { -DWIDE } ] +set torture_with_loops [list { } { -DWIDE } ] +set torture_without_loops [list { } { -DWIDE } ] + +# Need to copy the format.h header. +if [is_remote host] { + remote_download host $srcdir/$subdir/format.h +} + +load_lib gcc-dg.exp + +dg-init +gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] "" +if [info exists old_TORTURE_OPTIONS] { + set TORTURE_OPTIONS $old_TORTURE_OPTIONS +} else { + unset TORTURE_OPTIONS +} +if [info exists old_torture_with_loops] { + set torture_with_loops $old_torture_with_loops +} else { + unset torture_with_loops +} +if [info exists old_torture_without_loops] { + set torture_without_loops $old_torture_without_loops +} else { + unset torture_without_loops +} +dg-finish Index: ext-5.c =================================================================== --- ext-5.c (nonexistent) +++ ext-5.c (revision 154) @@ -0,0 +1,17 @@ +/* Test for gettext default attributes. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (int i, long l) +{ + printf (gettext ("%d"), i); + printf (gettext ("%ld"), i); /* { dg-warning "format" "gettext" } */ + printf (dgettext ("", "%d"), i); + printf (dgettext ("", "%ld"), i); /* { dg-warning "format" "dgettext" } */ + printf (dcgettext ("", "%d", 0), i); + printf (dcgettext ("", "%ld", 0), i); /* { dg-warning "format" "dcgettext" } */ +}
ext-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: no-exargs-2.c =================================================================== --- no-exargs-2.c (nonexistent) +++ no-exargs-2.c (revision 154) @@ -0,0 +1,27 @@ +/* Test for warnings for extra format arguments being disabled by + -Wno-format-extra-args. Test which warnings still apply with $ + operand numbers. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */ + +#include "format.h" + +void +foo (int i, int *ip, va_list va) +{ + printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */ + printf ("%2$d%1$d", i, i, i); + vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */ + /* With scanf formats, gaps in the used arguments are allowed only if the + arguments are all pointers. In such a case, should only give the lesser + warning about unused arguments rather than the more serious one about + argument gaps. */ + scanf ("%3$d%1$d", ip, ip, ip); + /* If there are non-pointer arguments unused at the end, this is also OK. */ + scanf ("%3$d%1$d", ip, ip, ip, i); + scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */ + /* Can't check the arguments in the vscanf case, so should suppose the + lesser problem. */ + vscanf ("%3$d%1$d", va); +}
no-exargs-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: va-1.c =================================================================== --- va-1.c (nonexistent) +++ va-1.c (revision 154) @@ -0,0 +1,13 @@ +/* Test for strange warning in format checking. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ + +#include "format.h" + +void +foo (void *p) +{ + printf ("%d", p); /* { dg-bogus "va_list" "wrong type in format warning" } */ + /* { dg-warning "format" "format error" { target *-*-* } 11 } */ +}
va-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: opt-5.c =================================================================== --- opt-5.c (nonexistent) +++ opt-5.c (revision 154) @@ -0,0 +1,7 @@ +/* Test diagnostics for options used on their own without + -Wformat. -Wformat-zero-length. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat-zero-length" } */ + +/* { dg-warning "warning: -Wformat-zero-length ignored without -Wformat" "ignored" { target *-*-* } 0 } */
opt-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: dfp-printf-1.c =================================================================== --- dfp-printf-1.c (nonexistent) +++ dfp-printf-1.c (revision 154) @@ -0,0 +1,122 @@ +/* Test for printf formats for Decimal Floating Point types. */ + +/* { dg-do compile } */ +/* { dg-require-effective-target dfp } */ +/* { dg-options "-Wformat" } */ + +extern int printf (const char *restrict, ...); + +void +foo (_Decimal32 x, _Decimal64 y, _Decimal128 z, int i, unsigned int j, + double d, char *p) +{ + /* See ISO/IEC DTR 24732 subclause 9.3 (currently Working Draft 5 from + 2005-03-06). */ + /* Formatted input/output specifiers. */ + + /* Check lack of warnings for valid usage. */ + + printf ("%Hf\n", x); + printf ("%HF\n", x); + printf ("%He\n", x); + printf ("%HE\n", x); + printf ("%Hg\n", x); + printf ("%HG\n", x); + + printf ("%Df\n", y); + printf ("%DF\n", y); + printf ("%De\n", y); + printf ("%DE\n", y); + printf ("%Dg\n", y); + printf ("%DG\n", y); + + printf ("%DDf\n", z); + printf ("%DDF\n", z); + printf ("%DDe\n", z); + printf ("%DDE\n", z); + printf ("%DDg\n", z); + printf ("%DDG\n", z); + + printf ("%DG%DDE%HF%DDe%He%HE%DF%DDF%De%DDG%HG%Df%Hg%DE%DDf%Dg%DDg%Hf\n", + y, z, x, z, x, x, y, z, y, z, x, y, x, y, z, y, z, x); + + /* Check warnings for type mismatches. */ + + printf ("%Hf\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HF\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%He\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HE\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%Hg\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HG\n", y); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%Hf\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HF\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%He\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HE\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%Hg\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + printf ("%HG\n", z); /* { dg-warning "expects type" "bad use of %H" } */ + + printf ("%Df\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DF\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%De\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DE\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%Dg\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DG\n", x); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%Df\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DF\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%De\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DE\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%Dg\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + printf ("%DG\n", z); /* { dg-warning "expects type" "bad use of %D" } */ + + printf ("%DDf\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDF\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDe\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDE\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDg\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDG\n", x); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDf\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDF\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDe\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDE\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDg\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + printf ("%DDG\n", y); /* { dg-warning "expects type" "bad use of %DD" } */ + + /* Check for warnings for bad use of H, D, and DD length specifiers. */ + + printf ("%Hd\n", i); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hi\n", i); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Ho\n", j); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hu\n", j); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hx\n", j); /* { dg-warning "length" "bad use of %H" } */ + printf ("%HX\n", j); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Ha\n", d); /* { dg-warning "length" "bad use of %H" } */ + printf ("%HA\n", d); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hc\n", i); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hs\n", p); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hp\n", p); /* { dg-warning "length" "bad use of %H" } */ + printf ("%Hn\n", p); /* { dg-warning "length" "bad use of %H" } */ + + /* Sanity checks for flags, field width, and precision in formats for + DFP types. */ + + printf ("%-Hf\n", x); + printf ("%+HF\n", x); + printf ("% He\n", x); + printf ("%#HE\n", x); + printf ("%0Hg\n", x); + printf ("%#0HG\n", x); + + printf ("%0#Df\n", y); + printf ("%0DF\n", y); + printf ("%#De\n", y); + printf ("%-#DE\n", y); + printf ("%-#0Dg\n", y); /* { dg-warning "flag ignored" "ignore flag" } */ + printf ("%0+ DG\n", y); /* { dg-warning "flag ignored" "ignore flag" } */ + + printf ("%DDf\n", z); + printf ("%0DDF\n", z); + printf ("%#0DDe\n", z); + printf ("%+DDE\n", z); + printf ("%0-#DDg\n", z); /* { dg-warning "flag ignored" "ignore flag" } */ + printf ("% DDG\n", z); +}
dfp-printf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-1.c =================================================================== --- attr-1.c (nonexistent) +++ attr-1.c (revision 154) @@ -0,0 +1,9 @@ +/* Test for strftime format attributes: can't have first_arg_num != 0. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +extern void foo0 (const char *) __attribute__((__format__(__strftime__, 1, 0))); +extern void foo1 (const char *, ...) __attribute__((__format__(__strftime__, 1, 2))); /* { dg-error "cannot format" "strftime first_arg_num != 0" } */
attr-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: sec-1.c =================================================================== --- sec-1.c (nonexistent) +++ sec-1.c (revision 154) @@ -0,0 +1,12 @@ +/* Test for security warning when non-literal format has no arguments. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat -Wformat-security" } */ + +#include "format.h" + +void +foo (char *s) +{ + printf (s); /* { dg-warning "no format arguments" "security warning" } */ +}
sec-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-3.c =================================================================== --- attr-3.c (nonexistent) +++ attr-3.c (revision 154) @@ -0,0 +1,70 @@ +/* Test for format attributes: test bad uses of __attribute__. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +/* Proper uses of the attributes. */ +extern void fa0 (const char *, ...) __attribute__((format(printf, 1, 2))); +extern void fa1 (char *, ...) __attribute__((format(printf, 1, 2))); +extern char *fa2 (const char *) __attribute__((format_arg(1))); +extern char *fa3 (char *) __attribute__((format_arg(1))); + +/* Uses with too few or too many arguments. */ +extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */ +extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */ +extern void fb2 (const char *, ...) __attribute__((format(printf))); /* { dg-error "wrong number of arguments" "bad format" } */ +extern void fb3 (const char *, ...) __attribute__((format(printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */ +extern void fb4 (const char *, ...) __attribute__((format(printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */ + +extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */ +extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */ +extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error "wrong number of arguments" "bad format_arg" } */ + +/* These attributes presently only apply to declarations, not to types. + Eventually, they should be usable with declarators for function types + anywhere, but still not with structure/union/enum types. */ +struct s0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */ +union u0 { int i; } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */ +enum e0 { E0V0 } __attribute__((format(printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */ + +struct s1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on struct" } */ +union u1 { int i; } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on union" } */ +enum e1 { E1V0 } __attribute__((format_arg(1))); /* { dg-error "does not apply|only applies" "format_arg on enum" } */ + +/* The format type must be an identifier, one of those recognized. */ +extern void fe0 (const char *, ...) __attribute__((format(12345, 1, 2))); /* { dg-error "format specifier" "non-id format" } */ +extern void fe1 (const char *, ...) __attribute__((format(nosuch, 1, 2))); /* { dg-warning "format function type" "unknown format" } */ + +/* Both the numbers must be integer constant expressions. */ +extern void ff0 (const char *, ...) __attribute__((format(printf, 3-2, (long long)(10/5)))); +int foo; +extern void ff1 (const char *, ...) __attribute__((format(printf, foo, 10/5))); /* { dg-error "invalid operand" "bad number" } */ +extern void ff2 (const char *, ...) __attribute__((format(printf, 3-2, foo))); /* { dg-error "invalid operand" "bad number" } */ +extern char *ff3 (const char *) __attribute__((format_arg(3-2))); +extern char *ff4 (const char *) __attribute__((format_arg(foo))); /* { dg-error "invalid operand" "bad format_arg number" } */ + +/* The format string argument must precede the arguments to be formatted. + This includes if no parameter types are specified (which is not valid ISO + C for variadic functions). */ +extern void fg0 () __attribute__((format(printf, 1, 2))); +extern void fg1 () __attribute__((format(printf, 1, 0))); +extern void fg2 () __attribute__((format(printf, 1, 1))); /* { dg-error "follows" "bad number order" } */ +extern void fg3 () __attribute__((format(printf, 2, 1))); /* { dg-error "follows" "bad number order" } */ + +/* The format string argument must be a string type, and the arguments to + be formatted must be the "...". */ +extern void fh0 (int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "format int string" } */ +extern void fh1 (signed char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "signed char string" } */ +extern void fh2 (unsigned char *, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "not a string" "unsigned char string" } */ +extern void fh3 (const char *, ...) __attribute__((format(printf, 1, 3))); /* { dg-error "is not" "not ..." } */ +extern void fh4 (const char *, int, ...) __attribute__((format(printf, 1, 2))); /* { dg-error "is not" "not ..." } */ + +/* format_arg formats must take and return a string. */ +extern char *fi0 (int) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg int string" } */ +extern char *fi1 (signed char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg signed char string" } */ +extern char *fi2 (unsigned char *) __attribute__((format_arg(1))); /* { dg-error "not a string" "format_arg unsigned char string" } */ +extern int fi3 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret int string" } */ +extern signed char *fi4 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret signed char string" } */ +extern unsigned char *fi5 (const char *) __attribute__((format_arg(1))); /* { dg-error "not return string" "format_arg ret unsigned char string" } */
attr-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-5.c =================================================================== --- attr-5.c (nonexistent) +++ attr-5.c (revision 154) @@ -0,0 +1,28 @@ +/* Test for format attributes: test default attributes are silently ignored + when a function is redeclared in an inappropriate manner. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +/* We can't #include "format.h" here. */ + +/* This scanf declaration is static, so can't be the system function. */ +static int scanf(const char *restrict, ...); + +/* This sscanf declaration doesn't have variable arguments, so isn't + compatible with a format attribute. */ +extern int sscanf(const char *restrict, const char *restrict, int *); /* { dg-warning "conflict" "conflict" } */ + +void +foo (const char *s, int *p) +{ + scanf("%ld", p); /* { dg-bogus "format" "static" } */ + sscanf(s, "%ld", p); /* { dg-bogus "format" "wrong type" } */ +} + +/* Dummy definition of scanf. */ +static int +scanf (const char *restrict fmt, ...) +{ + return 0; +}
attr-5.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: attr-7.c =================================================================== --- attr-7.c (nonexistent) +++ attr-7.c (revision 154) @@ -0,0 +1,34 @@ +/* Test for format attributes: test applying them to types. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +__attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...); +void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2))); +void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...); +void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...); + +char * (__attribute__((format_arg(1))) *tformat_arg) (const char *); + +void +baz (int i) +{ + (*tformatprintf0) ("%d", i); + (*tformatprintf0) ((*tformat_arg) ("%d"), i); + (*tformatprintf0) ("%"); /* { dg-warning "format" "prefix" } */ + (*tformatprintf0) ((*tformat_arg) ("%")); /* { dg-warning "format" "prefix" } */ + (*tformatprintf1) ("%d", i); + (*tformatprintf1) ((*tformat_arg) ("%d"), i); + (*tformatprintf1) ("%"); /* { dg-warning "format" "postfix" } */ + (*tformatprintf1) ((*tformat_arg) ("%")); /* { dg-warning "format" "postfix" } */ + (*tformatprintf2) ("%d", i); + (*tformatprintf2) ((*tformat_arg) ("%d"), i); + (*tformatprintf2) ("%"); /* { dg-warning "format" "nested" } */ + (*tformatprintf2) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested" } */ + (****tformatprintf3) ("%d", i); + (****tformatprintf3) ((*tformat_arg) ("%d"), i); + (****tformatprintf3) ("%"); /* { dg-warning "format" "nested 2" } */ + (****tformatprintf3) ((*tformat_arg) ("%")); /* { dg-warning "format" "nested 2" } */ +}
attr-7.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-scanf-1.c =================================================================== --- c90-scanf-1.c (nonexistent) +++ c90-scanf-1.c (revision 154) @@ -0,0 +1,119 @@ +/* Test for scanf formats. Formats using C90 features, including cases + where C90 specifies some aspect of the format to be ignored or where + the behavior is undefined. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp, + long int *lp, unsigned long int *ulp, float *fp, double *dp, + long double *ldp, char *s, signed char *ss, unsigned char *us, + void **pp, int *n, llong *llp, ullong *ullp, wchar_t *ls, + const int *cip, const int *cn, const char *cs, const void **ppc, + void *const *pcp, short int *hn, long int *ln, void *p, char **sp, + volatile void *ppv) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138). */ + /* Basic sanity checks for the different components of a format. */ + scanf ("%d", ip); + scanf ("%*d"); + scanf ("%3d", ip); + scanf ("%hd", hp); + scanf ("%3ld", lp); + scanf ("%*3d"); + scanf ("%d %ld", ip, lp); + /* Valid and invalid %% constructions. */ + scanf ("%%"); + scanf ("%*%"); /* { dg-warning "format" "bogus %%" } */ + scanf ("%*%\n"); /* { dg-warning "format" "bogus %%" } */ + scanf ("%4%"); /* { dg-warning "format" "bogus %%" } */ + scanf ("%4%\n"); /* { dg-warning "format" "bogus %%" } */ + scanf ("%h%"); /* { dg-warning "format" "bogus %%" } */ + scanf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */ + /* Valid, invalid and silly assignment-suppression constructions. */ + scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p"); + scanf ("%*2d%*8s%*3c"); + scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */ + scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */ + /* Valid, invalid and silly width constructions. */ + scanf ("%2d%3i%4o%5u%6x%7X%8e%9E%10f%11g%12G%13s%14[abc]%15c%16p", + ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, s, s, s, pp); + scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */ + scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */ + /* Valid and invalid %h, %l, %L constructions. */ + scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn); + scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hs", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hc", s); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */ + scanf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */ + scanf ("%h."); /* { dg-warning "conversion" "bogus %h" } */ + scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln); + scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp); + scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */ + /* These next three formats were added in C94. */ + scanf ("%ls", ls); /* { dg-warning "length|C" "bad use of %l" } */ + scanf ("%l[ac]", ls); /* { dg-warning "length|C" "bad use of %l" } */ + scanf ("%lc", ls); /* { dg-warning "length|C" "bad use of %l" } */ + scanf ("%Le%LE%Lf%Lg%LG", ldp, ldp, ldp, ldp, ldp); + scanf ("%Ld", llp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Li", llp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lo", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lu", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Lx", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%LX", ullp); /* { dg-warning "does not support" "bad use of %L" } */ + scanf ("%Ls", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%L[ac]", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Lc", s); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Lp", pp); /* { dg-warning "length" "bad use of %L" } */ + scanf ("%Ln", n); /* { dg-warning "length" "bad use of %L" } */ + /* Valid uses of each bare conversion. */ + scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip, + uip, fp, fp, fp, fp, fp, s, s, s, pp, n); + /* Allow other character pointers with %s, %c, %[]. */ + scanf ("%2s%3s%4c%5c%6[abc]%7[abc]", ss, us, ss, us, ss, us); + /* Further tests for %[]. */ + scanf ("%[%d]%d", s, ip); + scanf ("%[^%d]%d", s, ip); + scanf ("%[]%d]%d", s, ip); + scanf ("%[^]%d]%d", s, ip); + scanf ("%[%d]%d", s, ip); + scanf ("%[]abcd", s); /* { dg-warning "no closing" "incomplete scanset" } */ + /* Various tests of bad argument types. Some of these are only pedantic + warnings. + */ + scanf ("%d", lp); /* { dg-warning "format" "bad argument types" } */ + scanf ("%d", uip); /* { dg-warning "format" "bad argument types" } */ + scanf ("%d", pp); /* { dg-warning "format" "bad argument types" } */ + scanf ("%p", ppc); /* { dg-warning "format" "bad argument types" } */ + scanf ("%p", ppv); /* { dg-warning "format" "bad argument types" } */ + scanf ("%s", n); /* { dg-warning "format" "bad argument types" } */ + scanf ("%s", p); /* { dg-warning "format" "bad argument types" } */ + scanf ("%p", p); /* { dg-warning "format" "bad argument types" } */ + scanf ("%p", sp); /* { dg-warning "format" "bad argument types" } */ + /* Tests for writing into constant values. */ + scanf ("%d", cip); /* { dg-warning "constant" "%d writing into const" } */ + scanf ("%n", cn); /* { dg-warning "constant" "%n writing into const" } */ + scanf ("%s", cs); /* { dg-warning "constant" "%s writing into const" } */ + scanf ("%p", pcp); /* { dg-warning "constant" "%p writing into const" } */ + /* Wrong number of arguments. */ + scanf ("%d%d", ip); /* { dg-warning "arguments" "wrong number of args" } */ + scanf ("%d", ip, ip); /* { dg-warning "arguments" "wrong number of args" } */ + /* Miscellaneous bogus constructions. */ + scanf (""); /* { dg-warning "zero-length" "warning for empty format" } */ + scanf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */ + scanf ("%d\0", ip); /* { dg-warning "embedded" "warning for embedded NUL" } */ + scanf ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ + scanf (NULL); /* { dg-warning "null" "null format string warning" } */ + scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */ + scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */ +}
c90-scanf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c90-scanf-3.c =================================================================== --- c90-scanf-3.c (nonexistent) +++ c90-scanf-3.c (revision 154) @@ -0,0 +1,19 @@ +/* Test for scanf formats. Formats using extensions to the standard + should be rejected in strict pedantic mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (char **sp, wchar_t **lsp) +{ + /* %a formats for allocation, only recognized in C90 mode, are a + GNU extension. + */ + scanf ("%as", sp); /* { dg-warning "C" "%as" } */ + scanf ("%aS", lsp); /* { dg-warning "C" "%aS" } */ + scanf ("%a[bcd]", sp); /* { dg-warning "C" "%a[]" } */ +}
c90-scanf-3.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: unnamed-1.c =================================================================== --- unnamed-1.c (nonexistent) +++ unnamed-1.c (revision 154) @@ -0,0 +1,24 @@ +/* Test for warnings with possibly unnamed integer types. Bug 24329. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-Wformat" } */ +/* { dg-options "-Wformat -msse" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */ + + +#include "format.h" + +/* Definition of TItype follows same logic as in gcc.dg/titype-1.c, + but must be a #define to avoid giving the type a name. */ +#if defined(__LP64__) && !defined(__hppa__) +#define TItype int __attribute__ ((mode (TI))) +#else +#define TItype long +#endif + +void +f (TItype x) +{ + printf("%d", x); /* { dg-warning "expects type" } */ + printf("%d", 141592653589793238462643383279502884197169399375105820974944); /* { dg-warning "expects type" } */ + /* { dg-warning "unsigned only|too large" "constant" { target *-*-* } 22 } */ +}
unnamed-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c94-scanf-1.c =================================================================== --- c94-scanf-1.c (nonexistent) +++ c94-scanf-1.c (revision 154) @@ -0,0 +1,17 @@ +/* Test for scanf formats. Changes in C94 to C90. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:199409 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (wchar_t *ls) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138), + as amended by ISO/IEC 9899:1990/Amd.1:1995 (E) (pages 5-6). + We do not repeat here all the C90 format checks, but just verify + that %ls, %lc, %l[] are accepted without warning. + */ + scanf ("%lc%ls%l[abc]", ls, ls, ls); +}
c94-scanf-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: strfmon-1.c =================================================================== --- strfmon-1.c (nonexistent) +++ strfmon-1.c (revision 154) @@ -0,0 +1,63 @@ +/* Test for strfmon format checking. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void +foo (char *s, size_t m, double d, long double ld) +{ + /* Examples of valid formats from Austin Group draft 7. */ + strfmon (s, m, "%n", d); + strfmon (s, m, "%11n", d); + strfmon (s, m, "%#5n", d); + strfmon (s, m, "%=*#5n", d); + strfmon (s, m, "%=0#5n", d); + strfmon (s, m, "%^#5n", d); + strfmon (s, m, "%^#5.0n", d); + strfmon (s, m, "%^#5.4n", d); + strfmon (s, m, "%(#5n", d); + strfmon (s, m, "%!(#5n", d); + strfmon (s, m, "%-14#5.4n", d); + strfmon (s, m, "%14#5.4n", d); + /* Some more valid formats, including the GNU L length extension. */ + strfmon (s, m, "abc%-11ndef%==i%%", d, d); + strfmon (s, m, "%%abc%-11ndef%==Li%=%i", d, ld, d); + strfmon (s, m, "%Li", ld); + strfmon (s, m, "%11Li", ld); + strfmon (s, m, "%#5Li", ld); + strfmon (s, m, "%=*#5Li", ld); + strfmon (s, m, "%=0#5Li", ld); + strfmon (s, m, "%^#5Li", ld); + strfmon (s, m, "%^#5.0Li", ld); + strfmon (s, m, "%^#5.4Li", ld); + strfmon (s, m, "%(#5Li", ld); + strfmon (s, m, "%!(#5Li", ld); + strfmon (s, m, "%-14#5.4Li", ld); + strfmon (s, m, "%14#5.4Li", ld); + /* Formats with the wrong types used. */ + strfmon (s, m, "%Ln", d); /* { dg-warning "format" "wrong type" } */ + strfmon (s, m, "%n", ld); /* { dg-warning "format" "wrong type" } */ + /* The + and ( flags cannot be used together. */ + strfmon (s, m, "%+(i", d); /* { dg-warning "flag" "+ and ( flags" } */ + strfmon (s, m, "%(+i", d); /* { dg-warning "flag" "+ and ( flags" } */ + /* Although empty precision is OK for printf, it isn't here. */ + strfmon (s, m, "%#.5n", d); /* { dg-warning "empty" "empty left precision" } */ + strfmon (s, m, "%#5.n", d); /* { dg-warning "empty" "empty right precision" } */ + /* However, zero is a valid value for width and precisions. */ + strfmon (s, m, "%0#0.0n", d); + /* Test bogus %% constructions. */ + strfmon (s, m, "%^%"); /* { dg-warning "format" "bogus %%" } */ + strfmon (s, m, "%!%\n"); /* { dg-warning "format" "bogus %%" } */ + strfmon (s, m, "%5%\n"); /* { dg-warning "format" "bogus %%" } */ + strfmon (s, m, "%.5%\n"); /* { dg-warning "format" "bogus %%" } */ + strfmon (s, m, "%#5%\n"); /* { dg-warning "format" "bogus %%" } */ + /* Miscellaneous bogus formats. */ + strfmon (s, m, "%n%n", d); /* { dg-warning "arguments" "too few args" } */ + strfmon (s, m, ""); /* { dg-warning "zero-length" "empty" } */ + strfmon (s, m, NULL); /* { dg-warning "null" "null format string" } */ + strfmon (s, m, "%"); /* { dg-warning "trailing" "tailing %" } */ + strfmon (s, m, "%n\0", d); /* { dg-warning "embedded" "embedded NUL" } */ + strfmon (s, m, "%^^n", d); /* { dg-warning "repeated" "repeated flag" } */ +}
strfmon-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: xopen-2.c =================================================================== --- xopen-2.c (nonexistent) +++ xopen-2.c (revision 154) @@ -0,0 +1,21 @@ +/* Test for X/Open format extensions, as found in the + Single Unix Specification. Test for bug reported by + Pierre-Canalsat PETIT + in PR c/6547. The test for absence of a parameter for a * width was done + too early in the case of operand numbers and vprintf formats. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void vbar (va_list, const char *) __attribute__((__format__(__printf__, 2, 0))); + +void +foo (int i, int j, va_list va) +{ + printf("%2$*1$c", i, j); + printf("%2$*1$c %2$*1$c", i, j); /* { dg-bogus "too few" "bogus too few dollar" } */ + vbar(va, "%*s"); /* { dg-bogus "too few" "bogus too few vprintf" } */ +}
xopen-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-scanf-2.c =================================================================== --- c99-scanf-2.c (nonexistent) +++ c99-scanf-2.c (revision 154) @@ -0,0 +1,26 @@ +/* Test for scanf formats. Formats using extensions to the standard + should be rejected in strict pedantic mode. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ + +#include "format.h" + +void +foo (int *ip, long long int *llp, wchar_t *ls) +{ + /* The length modifiers q and L as applied to integer formats are + extensions. + */ + scanf ("%qd", llp); /* { dg-warning "C" "%q length" } */ + scanf ("%Ld", llp); /* { dg-warning "C" "%L length" } */ + /* The conversion specifiers C and S are X/Open extensions. */ + scanf ("%C", ls); /* { dg-warning "C" "scanf %C" } */ + scanf ("%S", ls); /* { dg-warning "C" "scanf %S" } */ + /* The use of operand number $ formats is an X/Open extension. */ + scanf ("%1$d", ip); /* { dg-warning "C" "scanf $ format" } */ + /* glibc also supports flags ' and I on scanf formats as an extension. */ + scanf ("%'d", ip); /* { dg-warning "C" "scanf ' flag" } */ + scanf ("%Id", ip); /* { dg-warning "C" "scanf I flag" } */ +}
c99-scanf-2.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: format.h =================================================================== --- format.h (nonexistent) +++ format.h (revision 154) @@ -0,0 +1,72 @@ +/* Format checking tests: common header. */ +/* Origin: Joseph Myers */ + +#include +#include + +#ifndef _WINT_T +#ifndef __WINT_TYPE__ +#define __WINT_TYPE__ unsigned int +#endif +typedef __WINT_TYPE__ wint_t; +#endif + +/* Kludges to get types corresponding to size_t and ptrdiff_t. */ +#define unsigned signed +typedef __SIZE_TYPE__ signed_size_t; +/* We also use this type to approximate ssize_t. */ +typedef __SIZE_TYPE__ ssize_t; +#undef unsigned +#define signed /* Type might or might not have explicit 'signed'. */ +typedef unsigned __PTRDIFF_TYPE__ unsigned_ptrdiff_t; +#undef signed + +__extension__ typedef long long int llong; +__extension__ typedef unsigned long long int ullong; + +/* %q formats want a "quad"; GCC considers this to be a long long. */ +typedef llong quad_t; +typedef ullong u_quad_t; + +__extension__ typedef __INTMAX_TYPE__ intmax_t; +__extension__ typedef __UINTMAX_TYPE__ uintmax_t; + +#if __STDC_VERSION__ < 199901L && !defined(restrict) +#define restrict /* "restrict" not in old C standard. */ +#endif + +/* This may not be correct in the particular case, but allows the + prototypes to be declared, and we don't try to link. +*/ +typedef struct _FILE FILE; +extern FILE *stdin; +extern FILE *stdout; + +extern int fprintf (FILE *restrict, const char *restrict, ...); +extern int printf (const char *restrict, ...); +extern int fprintf_unlocked (FILE *restrict, const char *restrict, ...); +extern int printf_unlocked (const char *restrict, ...); +extern int sprintf (char *restrict, const char *restrict, ...); +extern int vfprintf (FILE *restrict, const char *restrict, va_list); +extern int vprintf (const char *restrict, va_list); +extern int vsprintf (char *restrict, const char *restrict, va_list); +extern int snprintf (char *restrict, size_t, const char *restrict, ...); +extern int vsnprintf (char *restrict, size_t, const char *restrict, va_list); + +extern int fscanf (FILE *restrict, const char *restrict, ...); +extern int scanf (const char *restrict, ...); +extern int sscanf (const char *restrict, const char *restrict, ...); +extern int vfscanf (FILE *restrict, const char *restrict, va_list); +extern int vscanf (const char *restrict, va_list); +extern int vsscanf (const char *restrict, const char *restrict, va_list); + +extern char *gettext (const char *); +extern char *dgettext (const char *, const char *); +extern char *dcgettext (const char *, const char *, int); + +struct tm; + +extern size_t strftime (char *restrict, size_t, const char *restrict, + const struct tm *restrict); + +extern ssize_t strfmon (char *restrict, size_t, const char *restrict, ...);
format.h Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: c99-strftime-1.c =================================================================== --- c99-strftime-1.c (nonexistent) +++ c99-strftime-1.c (revision 154) @@ -0,0 +1,97 @@ +/* Test for strftime formats. Formats using C99 features. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1999 -pedantic -Wformat -Wformat-y2k" } */ + +#include "format.h" + +void +foo (char *s, size_t m, const struct tm *tp) +{ + /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175). */ + /* Formats which are Y2K-compliant (no 2-digit years). */ + strftime (s, m, "%a%A%b%B%C%d%e%F%G%h%H%I%j%m%M%p%R%S%t%T%u%U%V%w%W%X%Y%z%Z%%", tp); + strftime (s, m, "%EC%EX%EY%Od%Oe%OH%OI%Om%OM%OS%Ou%OU%OV%Ow%OW", tp); + /* Formats with 2-digit years. */ + strftime (s, m, "%D", tp); /* { dg-warning "only last 2" "2-digit year" } */ + strftime (s, m, "%g", tp); /* { dg-warning "only last 2" "2-digit year" } */ + strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */ + strftime (s, m, "%Oy", tp); /* { dg-warning "only last 2" "2-digit year" } */ + /* Formats with 2-digit years in some locales. */ + strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */ + strftime (s, m, "%Ec", tp); /* { dg-warning "some locales" "2-digit year" } */ + strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */ + strftime (s, m, "%Ex", tp); /* { dg-warning "some locales" "2-digit year" } */ + /* %Ey is explicitly an era offset not a 2-digit year; but in some + locales the E modifier may be ignored. + */ + strftime (s, m, "%Ey", tp); /* { dg-warning "some locales" "2-digit year" } */ + /* Bad uses of %E and %O. */ + strftime (s, m, "%EEY", tp); /* { dg-warning "multiple|repeated" "multiple %E/%O" } */ + strftime (s, m, "%EOy", tp); /* { dg-warning "multiple|together" "multiple %E/%O" } */ + strftime (s, m, "%OEy", tp); /* { dg-warning "multiple|together" "multiple %E/%O" } */ + strftime (s, m, "%OOV", tp); /* { dg-warning "multiple|repeated" "multiple %E/%O" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 31 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 32 } */ + strftime (s, m, "%Ea", tp); /* { dg-warning "flag|modifier" "bad %Ea" } */ + strftime (s, m, "%EA", tp); /* { dg-warning "flag|modifier" "bad %EA" } */ + strftime (s, m, "%Eb", tp); /* { dg-warning "flag|modifier" "bad %Eb" } */ + strftime (s, m, "%EB", tp); /* { dg-warning "flag|modifier" "bad %EB" } */ + strftime (s, m, "%Ed", tp); /* { dg-warning "flag|modifier" "bad %Ed" } */ + strftime (s, m, "%ED", tp); /* { dg-warning "flag|modifier" "bad %ED" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 41 } */ + strftime (s, m, "%Ee", tp); /* { dg-warning "flag|modifier" "bad %Ee" } */ + strftime (s, m, "%EF", tp); /* { dg-warning "flag|modifier" "bad %EF" } */ + strftime (s, m, "%Eg", tp); /* { dg-warning "flag|modifier" "bad %Eg" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 45 } */ + strftime (s, m, "%EG", tp); /* { dg-warning "flag|modifier" "bad %EG" } */ + strftime (s, m, "%Eh", tp); /* { dg-warning "flag|modifier" "bad %Eh" } */ + strftime (s, m, "%EH", tp); /* { dg-warning "flag|modifier" "bad %EH" } */ + strftime (s, m, "%EI", tp); /* { dg-warning "flag|modifier" "bad %EI" } */ + strftime (s, m, "%Ej", tp); /* { dg-warning "flag|modifier" "bad %Ej" } */ + strftime (s, m, "%Em", tp); /* { dg-warning "flag|modifier" "bad %Em" } */ + strftime (s, m, "%EM", tp); /* { dg-warning "flag|modifier" "bad %EM" } */ + strftime (s, m, "%En", tp); /* { dg-warning "flag|modifier" "bad %En" } */ + strftime (s, m, "%Ep", tp); /* { dg-warning "flag|modifier" "bad %Ep" } */ + strftime (s, m, "%Er", tp); /* { dg-warning "flag|modifier" "bad %Er" } */ + strftime (s, m, "%ER", tp); /* { dg-warning "flag|modifier" "bad %ER" } */ + strftime (s, m, "%ES", tp); /* { dg-warning "flag|modifier" "bad %ES" } */ + strftime (s, m, "%Et", tp); /* { dg-warning "flag|modifier" "bad %Et" } */ + strftime (s, m, "%ET", tp); /* { dg-warning "flag|modifier" "bad %ET" } */ + strftime (s, m, "%Eu", tp); /* { dg-warning "flag|modifier" "bad %Eu" } */ + strftime (s, m, "%EU", tp); /* { dg-warning "flag|modifier" "bad %EU" } */ + strftime (s, m, "%EV", tp); /* { dg-warning "flag|modifier" "bad %EV" } */ + strftime (s, m, "%Ew", tp); /* { dg-warning "flag|modifier" "bad %Ew" } */ + strftime (s, m, "%EW", tp); /* { dg-warning "flag|modifier" "bad %EW" } */ + strftime (s, m, "%Ez", tp); /* { dg-warning "flag|modifier" "bad %Ez" } */ + strftime (s, m, "%EZ", tp); /* { dg-warning "flag|modifier" "bad %EZ" } */ + strftime (s, m, "%E%", tp); /* { dg-warning "flag|modifier" "bad %E%" } */ + strftime (s, m, "%Oa", tp); /* { dg-warning "flag|modifier" "bad %Oa" } */ + strftime (s, m, "%OA", tp); /* { dg-warning "flag|modifier" "bad %OA" } */ + strftime (s, m, "%Ob", tp); /* { dg-warning "flag|modifier" "bad %Ob" } */ + strftime (s, m, "%OB", tp); /* { dg-warning "flag|modifier" "bad %OB" } */ + strftime (s, m, "%Oc", tp); /* { dg-warning "flag|modifier" "bad %Oc" } */ + /* { dg-warning "in some locales" "2-digit year" { target *-*-* } 73 } */ + strftime (s, m, "%OC", tp); /* { dg-warning "flag|modifier|C" "bad %OC" } */ + strftime (s, m, "%OD", tp); /* { dg-warning "flag|modifier" "bad %OD" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 76 } */ + strftime (s, m, "%OF", tp); /* { dg-warning "flag|modifier" "bad %OF" } */ + strftime (s, m, "%Og", tp); /* { dg-warning "flag|modifier|C" "bad %Og" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 79 } */ + strftime (s, m, "%OG", tp); /* { dg-warning "flag|modifier|C" "bad %OG" } */ + strftime (s, m, "%Oh", tp); /* { dg-warning "flag|modifier" "bad %Oh" } */ + strftime (s, m, "%Oj", tp); /* { dg-warning "flag|modifier|C" "bad %Oj" } */ + strftime (s, m, "%On", tp); /* { dg-warning "flag|modifier" "bad %On" } */ + strftime (s, m, "%Op", tp); /* { dg-warning "flag|modifier" "bad %Op" } */ + strftime (s, m, "%Or", tp); /* { dg-warning "flag|modifier" "bad %Or" } */ + strftime (s, m, "%OR", tp); /* { dg-warning "flag|modifier" "bad %OR" } */ + strftime (s, m, "%Ot", tp); /* { dg-warning "flag|modifier" "bad %Ot" } */ + strftime (s, m, "%OT", tp); /* { dg-warning "flag|modifier" "bad %OT" } */ + strftime (s, m, "%Ox", tp); /* { dg-warning "flag|modifier" "bad %Ox" } */ + /* { dg-warning "in some locales" "2-digit year" { target *-*-* } 90 } */ + strftime (s, m, "%OX", tp); /* { dg-warning "flag|modifier" "bad %OX" } */ + strftime (s, m, "%OY", tp); /* { dg-warning "flag|modifier|C" "bad %OY" } */ + strftime (s, m, "%Oz", tp); /* { dg-warning "flag|modifier|C" "bad %Oz" } */ + strftime (s, m, "%OZ", tp); /* { dg-warning "flag|modifier" "bad %OZ" } */ + strftime (s, m, "%O%", tp); /* { dg-warning "flag|modifier" "bad %O%" } */ +}
c99-strftime-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property Index: warnll-1.c =================================================================== --- warnll-1.c (nonexistent) +++ warnll-1.c (revision 154) @@ -0,0 +1,45 @@ +/* Test for printf formats. C99 "long long" formats should be accepted with + -Wno-long-long. +*/ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic -Wformat -Wno-long-long" } */ + +#include "format.h" + +void +foo (long long ll, unsigned long long ull, long long *lln, + long long *llp, unsigned long long *ullp) +{ + /* Test for accepting standard "long long" formats. */ + printf ("%lld%lli%llo%llu%llx%llX%lln", ll, ll, ull, ull, ull, ull, lln); + scanf ("%lld%lli%llo%llu%llx%llX%lln", llp, llp, + ullp, ullp, ullp, ullp, lln); + /* Use of "q" and "L" should still be warned about. */ + printf ("%qd", ll); /* { dg-warning "C" "printf %qd" } */ + printf ("%qi", ll); /* { dg-warning "C" "printf %qi" } */ + printf ("%qo", ull); /* { dg-warning "C" "printf %qo" } */ + printf ("%qu", ull); /* { dg-warning "C" "printf %qu" } */ + printf ("%qx", ull); /* { dg-warning "C" "printf %qx" } */ + printf ("%qX", ull); /* { dg-warning "C" "printf %qX" } */ + printf ("%qn", lln); /* { dg-warning "C" "printf %qn" } */ + printf ("%Ld", ll); /* { dg-warning "C" "printf %Ld" } */ + printf ("%Li", ll); /* { dg-warning "C" "printf %Li" } */ + printf ("%Lo", ull); /* { dg-warning "C" "printf %oL" } */ + printf ("%Lu", ull); /* { dg-warning "C" "printf %Lu" } */ + printf ("%Lx", ull); /* { dg-warning "C" "printf %Lx" } */ + printf ("%LX", ull); /* { dg-warning "C" "printf %LX" } */ + scanf ("%qd", llp); /* { dg-warning "C" "scanf %qd" } */ + scanf ("%qi", llp); /* { dg-warning "C" "scanf %qi" } */ + scanf ("%qo", ullp); /* { dg-warning "C" "scanf %qo" } */ + scanf ("%qu", ullp); /* { dg-warning "C" "scanf %qu" } */ + scanf ("%qx", ullp); /* { dg-warning "C" "scanf %qx" } */ + scanf ("%qX", ullp); /* { dg-warning "C" "scanf %qX" } */ + scanf ("%qn", lln); /* { dg-warning "C" "scanf %qn" } */ + scanf ("%Ld", llp); /* { dg-warning "C" "scanf %Ld" } */ + scanf ("%Li", llp); /* { dg-warning "C" "scanf %Li" } */ + scanf ("%Lo", ullp); /* { dg-warning "C" "scanf %oL" } */ + scanf ("%Lu", ullp); /* { dg-warning "C" "scanf %Lu" } */ + scanf ("%Lx", ullp); /* { dg-warning "C" "scanf %Lx" } */ + scanf ("%LX", ullp); /* { dg-warning "C" "scanf %LX" } */ +}
warnll-1.c Property changes : Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Id \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.