summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/format-strings-ms.c
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-09-04 21:39:46 +0000
committerHans Wennborg <hans@hanshq.net>2014-09-04 21:39:46 +0000
commit68f42b95150281a6b8f031a8ec4c820aec8fd163 (patch)
treea28cac5b1084ee4e7fff04f4a500b91bf3dc215c /clang/test/Sema/format-strings-ms.c
parentf537aeaea123d9a0258e95e91ae3d07c723ad26f (diff)
downloadbcm5719-llvm-68f42b95150281a6b8f031a8ec4c820aec8fd163.tar.gz
bcm5719-llvm-68f42b95150281a6b8f031a8ec4c820aec8fd163.zip
MS format strings: support the 'w' length modifier (PR20808)
llvm-svn: 217195
Diffstat (limited to 'clang/test/Sema/format-strings-ms.c')
-rw-r--r--clang/test/Sema/format-strings-ms.c67
1 files changed, 54 insertions, 13 deletions
diff --git a/clang/test/Sema/format-strings-ms.c b/clang/test/Sema/format-strings-ms.c
index 2ad8eae033d..3daa0e4f1d5 100644
--- a/clang/test/Sema/format-strings-ms.c
+++ b/clang/test/Sema/format-strings-ms.c
@@ -1,25 +1,66 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 -Wformat-non-iso %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -triple=i386-pc-win32 -Wformat-non-iso -DNON_ISO_WARNING %s
int printf(const char *format, ...) __attribute__((format(printf, 1, 2)));
+int scanf(const char * restrict, ...) ;
+typedef unsigned short wchar_t;
+
+#ifdef NON_ISO_WARNING
+
+// Split off this test to reduce the warning noise in the rest of the file.
+void non_iso_warning_test(__int32 i32, __int64 i64, wchar_t c) {
+ printf("%Id", i32); // expected-warning{{'I' length modifier is not supported by ISO C}}
+ printf("%I32d", i32); // expected-warning{{'I32' length modifier is not supported by ISO C}}
+ printf("%I64d", i64); // expected-warning{{'I64' length modifier is not supported by ISO C}}
+ printf("%wc", c); // expected-warning{{'w' length modifier is not supported by ISO C}}
+}
+
+#else
void signed_test() {
short val = 30;
- printf("val = %I64d\n", val); // expected-warning{{'I64' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type '__int64' (aka 'long long') but the argument has type 'short'}}
+ printf("val = %I64d\n", val); // expected-warning{{format specifies type '__int64' (aka 'long long') but the argument has type 'short'}}
long long bigval = 30;
- printf("val = %I32d\n", bigval); // expected-warning{{'I32' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
- printf("val = %Id\n", bigval); // expected-warning{{'I' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
+ printf("val = %I32d\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
+ printf("val = %Id\n", bigval); // expected-warning{{format specifies type '__int32' (aka 'int') but the argument has type 'long long'}}
}
void unsigned_test() {
unsigned short val = 30;
- printf("val = %I64u\n", val); // expected-warning{{'I64' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type 'unsigned __int64' (aka 'unsigned long long') but the argument has type 'unsigned short'}}
+ printf("val = %I64u\n", val); // expected-warning{{format specifies type 'unsigned __int64' (aka 'unsigned long long') but the argument has type 'unsigned short'}}
unsigned long long bigval = 30;
- printf("val = %I32u\n", bigval); // expected-warning{{'I32' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
- printf("val = %Iu\n", bigval); // expected-warning{{'I' length modifier is not supported by ISO C}} \
- // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
+ printf("val = %I32u\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
+ printf("val = %Iu\n", bigval); // expected-warning{{format specifies type 'unsigned __int32' (aka 'unsigned int') but the argument has type 'unsigned long long'}}
}
+
+void w_test(wchar_t c, wchar_t *s) {
+ printf("%wc", c);
+ printf("%wC", c);
+ printf("%C", c);
+ printf("%ws", s);
+ printf("%wS", s);
+ printf("%S", s);
+ scanf("%wc", &c);
+ scanf("%wC", &c);
+ scanf("%C", &c);
+ scanf("%ws", s);
+ scanf("%wS", s);
+ scanf("%S", s);
+
+ double bad;
+ printf("%wc", bad); // expected-warning{{format specifies type 'wint_t' (aka 'int') but the argument has type 'double'}}
+ printf("%wC", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
+ printf("%C", bad); // expected-warning{{format specifies type 'wchar_t' (aka 'unsigned short') but the argument has type 'double'}}
+ printf("%ws", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
+ printf("%wS", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
+ printf("%S", bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double'}}
+ scanf("%wc", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+ scanf("%wC", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+ scanf("%C", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+ scanf("%ws", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+ scanf("%wS", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+ scanf("%S", &bad); // expected-warning{{format specifies type 'wchar_t *' (aka 'unsigned short *') but the argument has type 'double *'}}
+
+}
+
+#endif
OpenPOWER on IntegriCloud