OSDN Git Service

54d4655ef2ce4cb2402aae915a2e09a0fc44d3a5
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / format / attr-2.c
1 /* Test for format attributes: test use of __attribute__.  */
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu99 -Wformat" } */
5
6 #include "format.h"
7
8 extern void tformatprintf (const char *, ...) __attribute__((format(printf, 1, 2)));
9 extern void tformat__printf__ (const char *, ...) __attribute__((format(__printf__, 1, 2)));
10 extern void tformatscanf (const char *, ...) __attribute__((format(scanf, 1, 2)));
11 extern void tformat__scanf__ (const char *, ...) __attribute__((format(__scanf__, 1, 2)));
12 extern void tformatstrftime (const char *) __attribute__((format(strftime, 1, 0)));
13 extern void tformat__strftime__ (const char *) __attribute__((format(__strftime__, 1, 0)));
14 extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2)));
15 extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2)));
16 extern void t__format__printf (const char *, ...) __attribute__((__format__(printf, 1, 2)));
17 extern void t__format____printf__ (const char *, ...) __attribute__((__format__(__printf__, 1, 2)));
18 extern void t__format__scanf (const char *, ...) __attribute__((__format__(scanf, 1, 2)));
19 extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(__scanf__, 1, 2)));
20 extern void t__format__strftime (const char *) __attribute__((__format__(strftime, 1, 0)));
21 extern void t__format____strftime__ (const char *) __attribute__((__format__(__strftime__, 1, 0)));
22 extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2)));
23 extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2)));
24
25 extern char *tformat_arg (const char *) __attribute__((format_arg(1)));
26 extern char *t__format_arg__ (const char *) __attribute__((__format_arg__(1)));
27
28 void
29 foo (int i, int *ip, double d)
30 {
31   tformatprintf ("%d", i);
32   tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */
33   tformat__printf__ ("%d", i);
34   tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */
35   tformatscanf ("%d", ip);
36   tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */
37   tformat__scanf__ ("%d", ip);
38   tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */
39   tformatstrftime ("%a");
40   tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */
41   tformat__strftime__ ("%a");
42   tformat__strftime__ ("%"); /* { dg-warning "format" "attribute format __strftime__" } */
43   tformatstrfmon ("%n", d);
44   tformatstrfmon ("%"); /* { dg-warning "format" "attribute format strfmon" } */
45   tformat__strfmon__ ("%n", d);
46   tformat__strfmon__ ("%"); /* { dg-warning "format" "attribute format __strfmon__" } */
47   t__format__printf ("%d", i);
48   t__format__printf ("%"); /* { dg-warning "format" "attribute __format__ printf" } */
49   t__format____printf__ ("%d", i);
50   t__format____printf__ ("%"); /* { dg-warning "format" "attribute __format__ __printf__" } */
51   t__format__scanf ("%d", ip);
52   t__format__scanf ("%"); /* { dg-warning "format" "attribute __format__ scanf" } */
53   t__format____scanf__ ("%d", ip);
54   t__format____scanf__ ("%"); /* { dg-warning "format" "attribute __format__ __scanf__" } */
55   t__format__strftime ("%a");
56   t__format__strftime ("%"); /* { dg-warning "format" "attribute __format__ strftime" } */
57   t__format____strftime__ ("%a");
58   t__format____strftime__ ("%"); /* { dg-warning "format" "attribute __format__ __strftime__" } */
59   t__format__strfmon ("%n", d);
60   t__format__strfmon ("%"); /* { dg-warning "format" "attribute __format__ strfmon" } */
61   t__format____strfmon__ ("%n", d);
62   t__format____strfmon__ ("%"); /* { dg-warning "format" "attribute __format__ __strfmon__" } */
63   tformatprintf (tformat_arg ("%d"), i);
64   tformatprintf (tformat_arg ("%")); /* { dg-warning "format" "attribute format_arg" } */
65   tformatprintf (t__format_arg__ ("%d"), i);
66   tformatprintf (t__format_arg__ ("%")); /* { dg-warning "format" "attribute __format_arg__" } */
67 }