1 // RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 %s 2 // RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 %s 3 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 %s 4 // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 %s 5 6 // RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -DALLOWED %s 7 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -DALLOWED %s 8 9 int printf(const char *restrict, ...); 10 int scanf(const char * restrict, ...) ; 11 12 void test() { 13 long notLongEnough = 1; 14 long long quiteLong = 2; 15 16 printf("%Ld", notLongEnough); // expected-warning {{format specifies type 'long long' but the argument has type 'long'}} 17 printf("%Ld", quiteLong); 18 19 #ifndef ALLOWED 20 // expected-warning@-4 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} 21 // expected-note@-5 {{did you mean to use 'll'?}} 22 23 // expected-warning@-6 {{length modifier 'L' results in undefined behavior or no effect with 'd' conversion specifier}} 24 // expected-note@-7 {{did you mean to use 'll'?}} 25 #endif 26 } 27 28 void testAlwaysInvalid() { 29 // We should not suggest 'll' here! 30 printf("%Lc", 'a'); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 'c' conversion specifier}} 31 printf("%Ls", "a"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} 32 } 33 34 #ifdef ALLOWED 35 // PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx 36 void printf_longlong(long long x, unsigned long long y) { 37 printf("%Ld", y); // no-warning 38 printf("%Lu", y); // no-warning 39 printf("%Lx", y); // no-warning 40 printf("%Ld", x); // no-warning 41 printf("%Lu", x); // no-warning 42 printf("%Lx", x); // no-warning 43 printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} 44 } 45 46 void scanf_longlong(long long *x, unsigned long long *y) { 47 scanf("%Ld", y); // no-warning 48 scanf("%Lu", y); // no-warning 49 scanf("%Lx", y); // no-warning 50 scanf("%Ld", x); // no-warning 51 scanf("%Lu", x); // no-warning 52 scanf("%Lx", x); // no-warning 53 scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}} 54 } 55 #endif 56