60 lines · c
1// RUN: %clang_cc1 -fsyntax-only -verify -triple i386-apple-darwin9 %s2// RUN: %clang_cc1 -fsyntax-only -verify -triple thumbv6-apple-ios4.0 %s3// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-mingw32 -DMS %s4// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-pc-win32 -DMS %s5 6// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux-gnu -DALLOWED %s7// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-unknown-freebsd -DALLOWED %s8 9int printf(const char *restrict, ...);10int scanf(const char * restrict, ...) ;11 12void test(void) {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 ALLOWED20 // 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#endif26 27#ifndef MS28 printf("%Z\n", quiteLong); // expected-warning{{invalid conversion specifier 'Z'}}29#endif30}31 32void testAlwaysInvalid(void) {33 // We should not suggest 'll' here!34 printf("%Lc", 'a'); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 'c' conversion specifier}}35 printf("%Ls", "a"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}36}37 38#ifdef ALLOWED39// PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx40void printf_longlong(long long x, unsigned long long y) {41 printf("%Ld", y); // no-warning42 printf("%Lu", y); // no-warning43 printf("%Lx", y); // no-warning44 printf("%Ld", x); // no-warning45 printf("%Lu", x); // no-warning46 printf("%Lx", x); // no-warning47 printf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}48}49 50void scanf_longlong(long long *x, unsigned long long *y) {51 scanf("%Ld", y); // no-warning52 scanf("%Lu", y); // no-warning53 scanf("%Lx", y); // no-warning54 scanf("%Ld", x); // no-warning55 scanf("%Lu", x); // no-warning56 scanf("%Lx", x); // no-warning57 scanf("%Ls", "hello"); // expected-warning {{length modifier 'L' results in undefined behavior or no effect with 's' conversion specifier}}58}59#endif60