diff options
author | dim <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-02-20 13:06:31 +0000 |
commit | 39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df (patch) | |
tree | a9243275843fbeaa590afc07ee888e006b8d54ea /test/Sema/format-strings.c | |
parent | 69b4eca4a4255ba43baa5c1d9bbdec3ec17f479e (diff) | |
download | FreeBSD-src-39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df.zip FreeBSD-src-39fcc9a984e2820e4ea0fa2ac4abd17d9f3a31df.tar.gz |
Vendor import of clang trunk r126079:
http://llvm.org/svn/llvm-project/cfe/trunk@126079
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 2325454..be506d7 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -174,7 +174,16 @@ void test10(int x, float f, int i, long long lli) { printf("%.0Lf", (long double) 1.0); // no-warning printf("%c\n", "x"); // expected-warning{{conversion specifies type 'int' but the argument has type 'char *'}} printf("%c\n", 1.23); // expected-warning{{conversion specifies type 'int' but the argument has type 'double'}} -} + printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid conversion specifier '!'}} +} + +typedef unsigned char uint8_t; + +void should_understand_small_integers() { + printf("%hhu", (short) 10); // expected-warning{{conversion specifies type 'unsigned char' but the argument has type 'short'}} + printf("%hu\n", (unsigned char) 1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'unsigned char'}} + printf("%hu\n", (uint8_t)1); // expected-warning{{conversion specifies type 'unsigned short' but the argument has type 'uint8_t'}} +} void test11(void *p, char *s) { printf("%p", p); // no-warning @@ -301,3 +310,33 @@ void pr7981(wint_t c, wchar_t c2) { printf("%lc", c2); // no-warning } +// <rdar://problem/8269537> -Wformat-security says NULL is not a string literal +void rdar8269537() { + // This is likely to crash in most cases, but -Wformat-nonliteral technically + // doesn't warn in this case. + printf(0); // no-warning +} + +// Handle functions with multiple format attributes. +extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...) + __attribute__((__format__(__printf__, 1, 0))) + __attribute__((__format__(__scanf__, 3, 4))); + +void rdar8332221(va_list ap, int *x, long *y) { + rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}} +} + +// PR8641 +void pr8641() { + printf("%#x\n", 10); + printf("%#X\n", 10); +} + +void posix_extensions() { + // Test %'d, "thousands grouping". + // <rdar://problem/8816343> + printf("%'d\n", 123456789); // no-warning + printf("%'i\n", 123456789); // no-warning + printf("%'f\n", (float) 1.0); // no-warning + printf("%'p\n", (void*) 0); // expected-warning{{results in undefined behavior with 'p' conversion specifier}} +} |