xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/format-strings-darwin.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-non-iso -DALLOWED %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 -Wformat-non-iso -DALLOWED %s
3f4a2713aSLionel Sambuc 
4*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -Wformat-non-iso %s
5*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -Wformat-non-iso %s
6f4a2713aSLionel Sambuc 
7*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -Wformat-non-iso %s
8*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -Wformat-non-iso %s
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc int printf(const char *restrict, ...);
11f4a2713aSLionel Sambuc int scanf(const char * restrict, ...) ;
12f4a2713aSLionel Sambuc 
test()13f4a2713aSLionel Sambuc void test() {
14f4a2713aSLionel Sambuc   int justRight = 1;
15f4a2713aSLionel Sambuc   long tooLong = 2;
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc   printf("%D", justRight);
18f4a2713aSLionel Sambuc   printf("%D", tooLong);
19f4a2713aSLionel Sambuc   printf("%U", justRight);
20f4a2713aSLionel Sambuc   printf("%U", tooLong);
21f4a2713aSLionel Sambuc   printf("%O", justRight);
22f4a2713aSLionel Sambuc   printf("%O", tooLong);
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc #ifdef ALLOWED
25f4a2713aSLionel Sambuc   // expected-warning@-8 {{'D' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'd'?}}
26f4a2713aSLionel Sambuc   // expected-warning@-8 {{'D' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'd'?}} expected-warning@-8 {{format specifies type 'int' but the argument has type 'long'}}
27f4a2713aSLionel Sambuc   // expected-warning@-8 {{'U' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'u'?}}
28f4a2713aSLionel Sambuc   // expected-warning@-8 {{'U' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'u'?}} expected-warning@-8 {{format specifies type 'unsigned int' but the argument has type 'long'}}
29f4a2713aSLionel Sambuc   // expected-warning@-8 {{'O' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'o'?}}
30f4a2713aSLionel Sambuc   // expected-warning@-8 {{'O' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'o'?}} expected-warning@-8 {{format specifies type 'unsigned int' but the argument has type 'long'}}
31f4a2713aSLionel Sambuc #else
32f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'D'}}
33f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'D'}}
34f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'U'}}
35f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'U'}}
36f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'O'}}
37f4a2713aSLionel Sambuc   // expected-warning@-15 {{invalid conversion specifier 'O'}}
38f4a2713aSLionel Sambuc #endif
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc #ifdef ALLOWED
testPrintf(short x,long y)42f4a2713aSLionel Sambuc void testPrintf(short x, long y) {
43f4a2713aSLionel Sambuc   printf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
44f4a2713aSLionel Sambuc   printf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
45f4a2713aSLionel Sambuc   printf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
46f4a2713aSLionel Sambuc   printf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
47f4a2713aSLionel Sambuc   printf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
48f4a2713aSLionel Sambuc   printf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc   printf("%+'0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
51f4a2713aSLionel Sambuc   printf("% '0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
52f4a2713aSLionel Sambuc   printf("%#0.5lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
53f4a2713aSLionel Sambuc   printf("%'0.5lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
54f4a2713aSLionel Sambuc }
55f4a2713aSLionel Sambuc 
testScanf(short * x,long * y)56f4a2713aSLionel Sambuc void testScanf(short *x, long *y) {
57f4a2713aSLionel Sambuc   scanf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
58f4a2713aSLionel Sambuc   scanf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
59f4a2713aSLionel Sambuc   scanf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
60f4a2713aSLionel Sambuc   scanf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
61f4a2713aSLionel Sambuc   scanf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
62f4a2713aSLionel Sambuc   scanf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
63f4a2713aSLionel Sambuc }
64f4a2713aSLionel Sambuc #endif
65