Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gcc.dg/format/ext-3.c @ 111:04ced10e8804
gcc 7
author | kono |
---|---|
date | Fri, 27 Oct 2017 22:46:09 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68:561a7518be6b | 111:04ced10e8804 |
---|---|
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 | |
10 void | |
11 foo (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 | |
89 /* Incorrect usages with Y2K problems. */ | |
90 strftime (s, m, "%5c", tp); /* { dg-warning "width" "bad %c" } */ | |
91 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
92 strftime (s, m, "%-c", tp); /* { dg-warning "flag" "bad %c" } */ | |
93 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
94 strftime (s, m, "%_c", tp); /* { dg-warning "flag" "bad %c" } */ | |
95 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
96 strftime (s, m, "%0c", tp); /* { dg-warning "flag" "bad %c" } */ | |
97 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
98 strftime (s, m, "%5D", tp); /* { dg-warning "width" "bad %D" } */ | |
99 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
100 strftime (s, m, "%-D", tp); /* { dg-warning "flag" "bad %D" } */ | |
101 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
102 strftime (s, m, "%_D", tp); /* { dg-warning "flag" "bad %D" } */ | |
103 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
104 strftime (s, m, "%0D", tp); /* { dg-warning "flag" "bad %D" } */ | |
105 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
106 strftime (s, m, "%5x", tp); /* { dg-warning "width" "bad %x" } */ | |
107 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
108 strftime (s, m, "%-x", tp); /* { dg-warning "flag" "bad %x" } */ | |
109 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
110 strftime (s, m, "%_x", tp); /* { dg-warning "flag" "bad %x" } */ | |
111 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
112 strftime (s, m, "%0x", tp); /* { dg-warning "flag" "bad %x" } */ | |
113 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
114 | |
115 /* Incorrect usages with GNU extension conversion characters. */ | |
116 strftime (s, m, "%5P", tp); /* { dg-warning "width" "bad %P" } */ | |
117 strftime (s, m, "%-P", tp); /* { dg-warning "flag" "bad %P" } */ | |
118 strftime (s, m, "%_P", tp); /* { dg-warning "flag" "bad %P" } */ | |
119 strftime (s, m, "%0P", tp); /* { dg-warning "flag" "bad %P" } */ | |
120 /* The "^" and "#" flags control the case of the output. | |
121 ^ (uppercase) makes sense on aAbBhZ; # (change case) makes sense | |
122 on the same and on p. | |
123 */ | |
124 strftime (s, m, "%^a%#a%^A%#A%^b%#b%^B%#B%^h%#h%^Z%#Z%#p", tp); | |
125 /* Bad usages. */ | |
126 strftime (s, m, "%^C", tp); /* { dg-warning "flag" "bad %C" } */ | |
127 strftime (s, m, "%#C", tp); /* { dg-warning "flag" "bad %C" } */ | |
128 strftime (s, m, "%^d", tp); /* { dg-warning "flag" "bad %d" } */ | |
129 strftime (s, m, "%#d", tp); /* { dg-warning "flag" "bad %d" } */ | |
130 strftime (s, m, "%^e", tp); /* { dg-warning "flag" "bad %e" } */ | |
131 strftime (s, m, "%#e", tp); /* { dg-warning "flag" "bad %e" } */ | |
132 strftime (s, m, "%^F", tp); /* { dg-warning "flag" "bad %F" } */ | |
133 strftime (s, m, "%#F", tp); /* { dg-warning "flag" "bad %F" } */ | |
134 strftime (s, m, "%^G", tp); /* { dg-warning "flag" "bad %G" } */ | |
135 strftime (s, m, "%#G", tp); /* { dg-warning "flag" "bad %G" } */ | |
136 strftime (s, m, "%^H", tp); /* { dg-warning "flag" "bad %H" } */ | |
137 strftime (s, m, "%#H", tp); /* { dg-warning "flag" "bad %H" } */ | |
138 strftime (s, m, "%^I", tp); /* { dg-warning "flag" "bad %I" } */ | |
139 strftime (s, m, "%#I", tp); /* { dg-warning "flag" "bad %I" } */ | |
140 strftime (s, m, "%^j", tp); /* { dg-warning "flag" "bad %j" } */ | |
141 strftime (s, m, "%#j", tp); /* { dg-warning "flag" "bad %j" } */ | |
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, "%^M", tp); /* { dg-warning "flag" "bad %M" } */ | |
145 strftime (s, m, "%#M", tp); /* { dg-warning "flag" "bad %M" } */ | |
146 strftime (s, m, "%^n", tp); /* { dg-warning "flag" "bad %n" } */ | |
147 strftime (s, m, "%#n", tp); /* { dg-warning "flag" "bad %n" } */ | |
148 strftime (s, m, "%^p", tp); /* { dg-warning "flag" "bad %p" } */ | |
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, "%^R", tp); /* { dg-warning "flag" "bad %R" } */ | |
152 strftime (s, m, "%#R", tp); /* { dg-warning "flag" "bad %R" } */ | |
153 strftime (s, m, "%^S", tp); /* { dg-warning "flag" "bad %S" } */ | |
154 strftime (s, m, "%#S", tp); /* { dg-warning "flag" "bad %S" } */ | |
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, "%^T", tp); /* { dg-warning "flag" "bad %T" } */ | |
158 strftime (s, m, "%#T", tp); /* { dg-warning "flag" "bad %T" } */ | |
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, "%^U", tp); /* { dg-warning "flag" "bad %U" } */ | |
162 strftime (s, m, "%#U", tp); /* { dg-warning "flag" "bad %U" } */ | |
163 strftime (s, m, "%^V", tp); /* { dg-warning "flag" "bad %V" } */ | |
164 strftime (s, m, "%#V", tp); /* { dg-warning "flag" "bad %V" } */ | |
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, "%^W", tp); /* { dg-warning "flag" "bad %W" } */ | |
168 strftime (s, m, "%#W", tp); /* { dg-warning "flag" "bad %W" } */ | |
169 strftime (s, m, "%^X", tp); /* { dg-warning "flag" "bad %X" } */ | |
170 strftime (s, m, "%#X", tp); /* { dg-warning "flag" "bad %X" } */ | |
171 strftime (s, m, "%^Y", tp); /* { dg-warning "flag" "bad %Y" } */ | |
172 strftime (s, m, "%#Y", tp); /* { dg-warning "flag" "bad %Y" } */ | |
173 strftime (s, m, "%^z", tp); /* { dg-warning "flag" "bad %z" } */ | |
174 strftime (s, m, "%#z", tp); /* { dg-warning "flag" "bad %z" } */ | |
175 strftime (s, m, "%^P", tp); /* { dg-warning "flag" "bad %P" } */ | |
176 strftime (s, m, "%#P", tp); /* { dg-warning "flag" "bad %P" } */ | |
177 strftime (s, m, "%^k", tp); /* { dg-warning "flag" "bad %k" } */ | |
178 strftime (s, m, "%#k", tp); /* { dg-warning "flag" "bad %k" } */ | |
179 strftime (s, m, "%^l", tp); /* { dg-warning "flag" "bad %l" } */ | |
180 strftime (s, m, "%#l", tp); /* { dg-warning "flag" "bad %l" } */ | |
181 strftime (s, m, "%^s", tp); /* { dg-warning "flag" "bad %s" } */ | |
182 strftime (s, m, "%#s", tp); /* { dg-warning "flag" "bad %s" } */ | |
183 | |
184 /* Bad usages with Y2K problems. */ | |
185 strftime (s, m, "%^c", tp); /* { dg-warning "flag" "bad %c" } */ | |
186 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
187 strftime (s, m, "%#c", tp); /* { dg-warning "flag" "bad %c" } */ | |
188 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
189 strftime (s, m, "%^D", tp); /* { dg-warning "flag" "bad %D" } */ | |
190 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
191 strftime (s, m, "%#D", tp); /* { dg-warning "flag" "bad %D" } */ | |
192 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
193 strftime (s, m, "%^g", tp); /* { dg-warning "flag" "bad %g" } */ | |
194 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
195 strftime (s, m, "%#g", tp); /* { dg-warning "flag" "bad %g" } */ | |
196 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
197 strftime (s, m, "%^x", tp); /* { dg-warning "flag" "bad %x" } */ | |
198 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
199 strftime (s, m, "%#x", tp); /* { dg-warning "flag" "bad %x" } */ | |
200 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
201 strftime (s, m, "%^y", tp); /* { dg-warning "flag" "bad %y" } */ | |
202 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
203 strftime (s, m, "%#y", tp); /* { dg-warning "flag" "bad %y" } */ | |
204 /* { dg-warning "only last 2" "2-digit year" { target *-*-* } .-1 } */ | |
205 | |
206 /* GCC also accepts the glibc format extensions %P, %k, %l, %s. */ | |
207 strftime (s, m, "%P%k%l%s", tp); | |
208 /* GCC also accepts the glibc extension of the "O" modifier on some | |
209 more formats. The cases where it is rejected altogether are | |
210 covered in c99-strftime-1.c, except for the extension %P. | |
211 */ | |
212 strftime (s, m, "%OC%Og%OG%Oj%OY%Oz%Ok%Ol%Os", tp); /* { dg-warning "only last 2" "2-digit year" } */ | |
213 strftime (s, m, "%OP", tp); /* { dg-warning "flag|modifier" "bad %OP" } */ | |
214 /* The "-", "_" and "0" flags are mutually exclusive. */ | |
215 strftime (s, m, "%-_5C", tp); /* { dg-warning "flag" "bad %-_" } */ | |
216 strftime (s, m, "%-05C", tp); /* { dg-warning "flag" "bad %-0" } */ | |
217 strftime (s, m, "%_05C", tp); /* { dg-warning "flag" "bad %_0" } */ | |
218 /* The "#" and "^" flags are mutually exclusive. */ | |
219 strftime (s, m, "%^#a", tp); /* { dg-warning "flag" "bad %^#" } */ | |
220 } |