1/* Test for format extensions beyond the C standard and X/Open standard.
2   Test for strftime formats.
3*/
4/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
5/* { dg-do compile } */
6/* { dg-options "-std=gnu99 -Wformat -Wformat-y2k" } */
7
8#include "format.h"
9
10void
11foo (char *s, size_t m, const struct tm *tp)
12{
13  /* GCC accepts the "-", "_" and "0" flags to control padding on numeric
14     formats.  It also accepts width on these formats.
15  */
16  /* Basic tests of parts on their own.  */
17  strftime (s, m, "%5C%-C%_C%0C", tp);
18  /* Correct usages.  */
19  strftime (s, m, "%-5C%_5C%05C%-5d%_5d%05d%-5e%_5e%05e%-5G%_5G%05G", tp);
20  strftime (s, m, "%-5H%_5H%05H%-5I%_5I%05I%-5j%_5j%05j%-5m%_5m%05m", tp);
21  strftime (s, m, "%-5M%_5M%05M%-5S%_5S%05S%-5u%_5u%05u%-5U%_5U%05U", tp);
22  strftime (s, m, "%-5V%_5V%05V%-5w%_5w%05w%-5W%_5W%05W%-5Y%_5Y%05Y", tp);
23  /* Correct usages with GNU extension conversion characters.  */
24  strftime (s, m, "%-5k%_5k%05k%-5l%_5l%05l%-20s%_20s%020s", tp);
25  /* Correct usages with Y2K problems.  */
26  strftime (s, m, "%-5g%_5g%05g%-5y%_5y%05y", tp); /* { dg-warning "only last 2" "2-digit year" } */
27  /* Incorrect usages.  */
28  strftime (s, m, "%5a", tp); /* { dg-warning "width" "bad %a" } */
29  strftime (s, m, "%-a", tp); /* { dg-warning "flag" "bad %a" } */
30  strftime (s, m, "%_a", tp); /* { dg-warning "flag" "bad %a" } */
31  strftime (s, m, "%0a", tp); /* { dg-warning "flag" "bad %a" } */
32  strftime (s, m, "%5A", tp); /* { dg-warning "width" "bad %A" } */
33  strftime (s, m, "%-A", tp); /* { dg-warning "flag" "bad %A" } */
34  strftime (s, m, "%_A", tp); /* { dg-warning "flag" "bad %A" } */
35  strftime (s, m, "%0A", tp); /* { dg-warning "flag" "bad %A" } */
36  strftime (s, m, "%5b", tp); /* { dg-warning "width" "bad %b" } */
37  strftime (s, m, "%-b", tp); /* { dg-warning "flag" "bad %b" } */
38  strftime (s, m, "%_b", tp); /* { dg-warning "flag" "bad %b" } */
39  strftime (s, m, "%0b", tp); /* { dg-warning "flag" "bad %b" } */
40  strftime (s, m, "%5B", tp); /* { dg-warning "width" "bad %B" } */
41  strftime (s, m, "%-B", tp); /* { dg-warning "flag" "bad %B" } */
42  strftime (s, m, "%_B", tp); /* { dg-warning "flag" "bad %B" } */
43  strftime (s, m, "%0B", tp); /* { dg-warning "flag" "bad %B" } */
44  strftime (s, m, "%5F", tp); /* { dg-warning "width" "bad %F" } */
45  strftime (s, m, "%-F", tp); /* { dg-warning "flag" "bad %F" } */
46  strftime (s, m, "%_F", tp); /* { dg-warning "flag" "bad %F" } */
47  strftime (s, m, "%0F", tp); /* { dg-warning "flag" "bad %F" } */
48  strftime (s, m, "%5h", tp); /* { dg-warning "width" "bad %h" } */
49  strftime (s, m, "%-h", tp); /* { dg-warning "flag" "bad %h" } */
50  strftime (s, m, "%_h", tp); /* { dg-warning "flag" "bad %h" } */
51  strftime (s, m, "%0h", tp); /* { dg-warning "flag" "bad %h" } */
52  strftime (s, m, "%5n", tp); /* { dg-warning "width" "bad %n" } */
53  strftime (s, m, "%-n", tp); /* { dg-warning "flag" "bad %n" } */
54  strftime (s, m, "%_n", tp); /* { dg-warning "flag" "bad %n" } */
55  strftime (s, m, "%0n", tp); /* { dg-warning "flag" "bad %n" } */
56  strftime (s, m, "%5p", tp); /* { dg-warning "width" "bad %p" } */
57  strftime (s, m, "%-p", tp); /* { dg-warning "flag" "bad %p" } */
58  strftime (s, m, "%_p", tp); /* { dg-warning "flag" "bad %p" } */
59  strftime (s, m, "%0p", tp); /* { dg-warning "flag" "bad %p" } */
60  strftime (s, m, "%5r", tp); /* { dg-warning "width" "bad %r" } */
61  strftime (s, m, "%-r", tp); /* { dg-warning "flag" "bad %r" } */
62  strftime (s, m, "%_r", tp); /* { dg-warning "flag" "bad %r" } */
63  strftime (s, m, "%0r", tp); /* { dg-warning "flag" "bad %r" } */
64  strftime (s, m, "%5R", tp); /* { dg-warning "width" "bad %R" } */
65  strftime (s, m, "%-R", tp); /* { dg-warning "flag" "bad %R" } */
66  strftime (s, m, "%_R", tp); /* { dg-warning "flag" "bad %R" } */
67  strftime (s, m, "%0R", tp); /* { dg-warning "flag" "bad %R" } */
68  strftime (s, m, "%5t", tp); /* { dg-warning "width" "bad %t" } */
69  strftime (s, m, "%-t", tp); /* { dg-warning "flag" "bad %t" } */
70  strftime (s, m, "%_t", tp); /* { dg-warning "flag" "bad %t" } */
71  strftime (s, m, "%0t", tp); /* { dg-warning "flag" "bad %t" } */
72  strftime (s, m, "%5T", tp); /* { dg-warning "width" "bad %T" } */
73  strftime (s, m, "%-T", tp); /* { dg-warning "flag" "bad %T" } */
74  strftime (s, m, "%_T", tp); /* { dg-warning "flag" "bad %T" } */
75  strftime (s, m, "%0T", tp); /* { dg-warning "flag" "bad %T" } */
76  strftime (s, m, "%5X", tp); /* { dg-warning "width" "bad %X" } */
77  strftime (s, m, "%-X", tp); /* { dg-warning "flag" "bad %X" } */
78  strftime (s, m, "%_X", tp); /* { dg-warning "flag" "bad %X" } */
79  strftime (s, m, "%0X", tp); /* { dg-warning "flag" "bad %X" } */
80  strftime (s, m, "%5z", tp); /* { dg-warning "width" "bad %z" } */
81  strftime (s, m, "%-z", tp); /* { dg-warning "flag" "bad %z" } */
82  strftime (s, m, "%_z", tp); /* { dg-warning "flag" "bad %z" } */
83  strftime (s, m, "%0z", tp); /* { dg-warning "flag" "bad %z" } */
84  strftime (s, m, "%5Z", tp); /* { dg-warning "width" "bad %Z" } */
85  strftime (s, m, "%-Z", tp); /* { dg-warning "flag" "bad %Z" } */
86  strftime (s, m, "%_Z", tp); /* { dg-warning "flag" "bad %Z" } */
87  strftime (s, m, "%0Z", tp); /* { dg-warning "flag" "bad %Z" } */
88  /* Incorrect usages with Y2K problems.  */
89  strftime (s, m, "%5c", tp); /* { dg-warning "width" "bad %c" } */
90  strftime (s, m, "%-c", tp); /* { dg-warning "flag" "bad %c" } */
91  strftime (s, m, "%_c", tp); /* { dg-warning "flag" "bad %c" } */
92  strftime (s, m, "%0c", tp); /* { dg-warning "flag" "bad %c" } */
93  strftime (s, m, "%5D", tp); /* { dg-warning "width" "bad %D" } */
94  strftime (s, m, "%-D", tp); /* { dg-warning "flag" "bad %D" } */
95  strftime (s, m, "%_D", tp); /* { dg-warning "flag" "bad %D" } */
96  strftime (s, m, "%0D", tp); /* { dg-warning "flag" "bad %D" } */
97  strftime (s, m, "%5x", tp); /* { dg-warning "width" "bad %x" } */
98  strftime (s, m, "%-x", tp); /* { dg-warning "flag" "bad %x" } */
99  strftime (s, m, "%_x", tp); /* { dg-warning "flag" "bad %x" } */
100  strftime (s, m, "%0x", tp); /* { dg-warning "flag" "bad %x" } */
101  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 89 } */
102  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 90 } */
103  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 91 } */
104  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 92 } */
105  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 93 } */
106  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 94 } */
107  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 95 } */
108  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 96 } */
109  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 97 } */
110  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 98 } */
111  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 99 } */
112  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 100 } */
113  /* Incorrect usages with GNU extension conversion characters.  */
114  strftime (s, m, "%5P", tp); /* { dg-warning "width" "bad %P" } */
115  strftime (s, m, "%-P", tp); /* { dg-warning "flag" "bad %P" } */
116  strftime (s, m, "%_P", tp); /* { dg-warning "flag" "bad %P" } */
117  strftime (s, m, "%0P", tp); /* { dg-warning "flag" "bad %P" } */
118  /* The "^" and "#" flags control the case of the output.
119     ^ (uppercase) makes sense on aAbBhZ; # (change case) makes sense
120     on the same and on p.
121  */
122  strftime (s, m, "%^a%#a%^A%#A%^b%#b%^B%#B%^h%#h%^Z%#Z%#p", tp);
123  /* Bad usages.  */
124  strftime (s, m, "%^C", tp); /* { dg-warning "flag" "bad %C" } */
125  strftime (s, m, "%#C", tp); /* { dg-warning "flag" "bad %C" } */
126  strftime (s, m, "%^d", tp); /* { dg-warning "flag" "bad %d" } */
127  strftime (s, m, "%#d", tp); /* { dg-warning "flag" "bad %d" } */
128  strftime (s, m, "%^e", tp); /* { dg-warning "flag" "bad %e" } */
129  strftime (s, m, "%#e", tp); /* { dg-warning "flag" "bad %e" } */
130  strftime (s, m, "%^F", tp); /* { dg-warning "flag" "bad %F" } */
131  strftime (s, m, "%#F", tp); /* { dg-warning "flag" "bad %F" } */
132  strftime (s, m, "%^G", tp); /* { dg-warning "flag" "bad %G" } */
133  strftime (s, m, "%#G", tp); /* { dg-warning "flag" "bad %G" } */
134  strftime (s, m, "%^H", tp); /* { dg-warning "flag" "bad %H" } */
135  strftime (s, m, "%#H", tp); /* { dg-warning "flag" "bad %H" } */
136  strftime (s, m, "%^I", tp); /* { dg-warning "flag" "bad %I" } */
137  strftime (s, m, "%#I", tp); /* { dg-warning "flag" "bad %I" } */
138  strftime (s, m, "%^j", tp); /* { dg-warning "flag" "bad %j" } */
139  strftime (s, m, "%#j", tp); /* { dg-warning "flag" "bad %j" } */
140  strftime (s, m, "%^m", tp); /* { dg-warning "flag" "bad %m" } */
141  strftime (s, m, "%#m", tp); /* { dg-warning "flag" "bad %m" } */
142  strftime (s, m, "%^M", tp); /* { dg-warning "flag" "bad %M" } */
143  strftime (s, m, "%#M", tp); /* { dg-warning "flag" "bad %M" } */
144  strftime (s, m, "%^n", tp); /* { dg-warning "flag" "bad %n" } */
145  strftime (s, m, "%#n", tp); /* { dg-warning "flag" "bad %n" } */
146  strftime (s, m, "%^p", tp); /* { dg-warning "flag" "bad %p" } */
147  strftime (s, m, "%^r", tp); /* { dg-warning "flag" "bad %r" } */
148  strftime (s, m, "%#r", tp); /* { dg-warning "flag" "bad %r" } */
149  strftime (s, m, "%^R", tp); /* { dg-warning "flag" "bad %R" } */
150  strftime (s, m, "%#R", tp); /* { dg-warning "flag" "bad %R" } */
151  strftime (s, m, "%^S", tp); /* { dg-warning "flag" "bad %S" } */
152  strftime (s, m, "%#S", tp); /* { dg-warning "flag" "bad %S" } */
153  strftime (s, m, "%^t", tp); /* { dg-warning "flag" "bad %t" } */
154  strftime (s, m, "%#t", tp); /* { dg-warning "flag" "bad %t" } */
155  strftime (s, m, "%^T", tp); /* { dg-warning "flag" "bad %T" } */
156  strftime (s, m, "%#T", tp); /* { dg-warning "flag" "bad %T" } */
157  strftime (s, m, "%^u", tp); /* { dg-warning "flag" "bad %u" } */
158  strftime (s, m, "%#u", tp); /* { dg-warning "flag" "bad %u" } */
159  strftime (s, m, "%^U", tp); /* { dg-warning "flag" "bad %U" } */
160  strftime (s, m, "%#U", tp); /* { dg-warning "flag" "bad %U" } */
161  strftime (s, m, "%^V", tp); /* { dg-warning "flag" "bad %V" } */
162  strftime (s, m, "%#V", tp); /* { dg-warning "flag" "bad %V" } */
163  strftime (s, m, "%^w", tp); /* { dg-warning "flag" "bad %w" } */
164  strftime (s, m, "%#w", tp); /* { dg-warning "flag" "bad %w" } */
165  strftime (s, m, "%^W", tp); /* { dg-warning "flag" "bad %W" } */
166  strftime (s, m, "%#W", tp); /* { dg-warning "flag" "bad %W" } */
167  strftime (s, m, "%^X", tp); /* { dg-warning "flag" "bad %X" } */
168  strftime (s, m, "%#X", tp); /* { dg-warning "flag" "bad %X" } */
169  strftime (s, m, "%^Y", tp); /* { dg-warning "flag" "bad %Y" } */
170  strftime (s, m, "%#Y", tp); /* { dg-warning "flag" "bad %Y" } */
171  strftime (s, m, "%^z", tp); /* { dg-warning "flag" "bad %z" } */
172  strftime (s, m, "%#z", tp); /* { dg-warning "flag" "bad %z" } */
173  strftime (s, m, "%^P", tp); /* { dg-warning "flag" "bad %P" } */
174  strftime (s, m, "%#P", tp); /* { dg-warning "flag" "bad %P" } */
175  strftime (s, m, "%^k", tp); /* { dg-warning "flag" "bad %k" } */
176  strftime (s, m, "%#k", tp); /* { dg-warning "flag" "bad %k" } */
177  strftime (s, m, "%^l", tp); /* { dg-warning "flag" "bad %l" } */
178  strftime (s, m, "%#l", tp); /* { dg-warning "flag" "bad %l" } */
179  strftime (s, m, "%^s", tp); /* { dg-warning "flag" "bad %s" } */
180  strftime (s, m, "%#s", tp); /* { dg-warning "flag" "bad %s" } */
181  /* Bad usages with Y2K problems.  */
182  strftime (s, m, "%^c", tp); /* { dg-warning "flag" "bad %c" } */
183  strftime (s, m, "%#c", tp); /* { dg-warning "flag" "bad %c" } */
184  strftime (s, m, "%^D", tp); /* { dg-warning "flag" "bad %D" } */
185  strftime (s, m, "%#D", tp); /* { dg-warning "flag" "bad %D" } */
186  strftime (s, m, "%^g", tp); /* { dg-warning "flag" "bad %g" } */
187  strftime (s, m, "%#g", tp); /* { dg-warning "flag" "bad %g" } */
188  strftime (s, m, "%^x", tp); /* { dg-warning "flag" "bad %x" } */
189  strftime (s, m, "%#x", tp); /* { dg-warning "flag" "bad %x" } */
190  strftime (s, m, "%^y", tp); /* { dg-warning "flag" "bad %y" } */
191  strftime (s, m, "%#y", tp); /* { dg-warning "flag" "bad %y" } */
192  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 182 } */
193  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 183 } */
194  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 184 } */
195  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 185 } */
196  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 186 } */
197  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 187 } */
198  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 188 } */
199  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 189 } */
200  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 190 } */
201  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 191 } */
202  /* GCC also accepts the glibc format extensions %P, %k, %l, %s.  */
203  strftime (s, m, "%P%k%l%s", tp);
204  /* GCC also accepts the glibc extension of the "O" modifier on some
205     more formats.  The cases where it is rejected altogether are
206     covered in c99-strftime-1.c, except for the extension %P.
207  */
208  strftime (s, m, "%OC%Og%OG%Oj%OY%Oz%Ok%Ol%Os", tp); /* { dg-warning "only last 2" "2-digit year" } */
209  strftime (s, m, "%OP", tp); /* { dg-warning "flag|modifier" "bad %OP" } */
210  /* The "-", "_" and "0" flags are mutually exclusive.  */
211  strftime (s, m, "%-_5C", tp); /* { dg-warning "flag" "bad %-_" } */
212  strftime (s, m, "%-05C", tp); /* { dg-warning "flag" "bad %-0" } */
213  strftime (s, m, "%_05C", tp); /* { dg-warning "flag" "bad %_0" } */
214  /* The "#" and "^" flags are mutually exclusive.  */
215  strftime (s, m, "%^#a", tp); /* { dg-warning "flag" "bad %^#" } */
216}
217