blob: 284cd26561347441d7e4e542301a1f75ad2c849b [file] [log] [blame]
Jordan Rose275b6f52012-09-13 02:11:03 +00001// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -pedantic -DALLOWED %s
2// RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 -pedantic -DALLOWED %s
3
4// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -pedantic %s
5// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -pedantic %s
6
7// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -pedantic %s
8// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -pedantic %s
9
10int printf(const char *restrict, ...);
11int scanf(const char * restrict, ...) ;
12
13void test() {
14 int justRight = 1;
15 long tooLong = 2;
16
17 printf("%D", justRight);
18 printf("%D", tooLong);
19 printf("%U", justRight);
20 printf("%U", tooLong);
21 printf("%O", justRight);
22 printf("%O", tooLong);
23
24#ifdef ALLOWED
25 // expected-warning@-8 {{'D' conversion specifier is not supported by ISO C}}
26 // expected-warning@-8 {{'D' conversion specifier is not supported by ISO C}} expected-warning@-8 {{format specifies type 'int' but the argument has type 'long'}}
27 // expected-warning@-8 {{'U' conversion specifier is not supported by ISO C}}
28 // expected-warning@-8 {{'U' conversion specifier is not supported by ISO C}} expected-warning@-8 {{format specifies type 'unsigned int' but the argument has type 'long'}}
29 // expected-warning@-8 {{'O' conversion specifier is not supported by ISO C}}
30 // expected-warning@-8 {{'O' conversion specifier is not supported by ISO C}} expected-warning@-8 {{format specifies type 'unsigned int' but the argument has type 'long'}}
31#else
32 // expected-warning@-15 {{invalid conversion specifier 'D'}}
33 // expected-warning@-15 {{invalid conversion specifier 'D'}}
34 // expected-warning@-15 {{invalid conversion specifier 'U'}}
35 // expected-warning@-15 {{invalid conversion specifier 'U'}}
36 // expected-warning@-15 {{invalid conversion specifier 'O'}}
37 // expected-warning@-15 {{invalid conversion specifier 'O'}}
38#endif
39}
40
41#ifdef ALLOWED
42void testPrintf(short x, long y) {
43 printf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}}
44 printf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}}
45 printf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}}
46 printf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}}
47 printf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}}
48 printf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}}
49
50 printf("%+'0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}}
51 printf("% '0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}}
52 printf("%#0.5lO", y); // expected-warning{{conversion specifier is not supported by ISO C}}
53 printf("%'0.5lU", y); // expected-warning{{conversion specifier is not supported by ISO C}}
54}
55
56void testScanf(short *x, long *y) {
57 scanf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}}
58 scanf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}}
59 scanf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}}
60 scanf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}}
61 scanf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}}
62 scanf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}}
63}
64#endif