blob: 46e717eb9d788ca89a95cd632f28aec916836f31 [file] [log] [blame]
Richard Smith1b98ccc2014-07-19 01:39:17 +00001// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 -Wformat-non-iso -DALLOWED %s
2// RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 -Wformat-non-iso -DALLOWED %s
Jordan Rose510260c2012-09-13 02:11:03 +00003
Richard Smith1b98ccc2014-07-19 01:39:17 +00004// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -Wformat-non-iso %s
5// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -Wformat-non-iso %s
Jordan Rose510260c2012-09-13 02:11:03 +00006
Richard Smith1b98ccc2014-07-19 01:39:17 +00007// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -Wformat-non-iso %s
8// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -Wformat-non-iso %s
Jordan Rose510260c2012-09-13 02:11:03 +00009
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
Jordan Rose4c266aa2012-09-13 02:11:15 +000025 // expected-warning@-8 {{'D' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'd'?}}
26 // 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'}}
27 // expected-warning@-8 {{'U' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'u'?}}
28 // 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'}}
29 // expected-warning@-8 {{'O' conversion specifier is not supported by ISO C}} expected-note@-8 {{did you mean to use 'o'?}}
30 // 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'}}
Jordan Rose510260c2012-09-13 02:11:03 +000031#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) {
Jordan Rose4c266aa2012-09-13 02:11:15 +000043 printf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
44 printf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
45 printf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
46 printf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
47 printf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
48 printf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
Jordan Rose510260c2012-09-13 02:11:03 +000049
Jordan Rose4c266aa2012-09-13 02:11:15 +000050 printf("%+'0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
51 printf("% '0.5lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
52 printf("%#0.5lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
53 printf("%'0.5lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
Jordan Rose510260c2012-09-13 02:11:03 +000054}
55
56void testScanf(short *x, long *y) {
Jordan Rose4c266aa2012-09-13 02:11:15 +000057 scanf("%hD", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
58 scanf("%lD", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'd'?}}
59 scanf("%hU", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
60 scanf("%lU", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'u'?}}
61 scanf("%hO", x); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
62 scanf("%lO", y); // expected-warning{{conversion specifier is not supported by ISO C}} expected-note {{did you mean to use 'o'?}}
Jordan Rose510260c2012-09-13 02:11:03 +000063}
64#endif