diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-27 01:41:03 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-27 01:41:03 +0000 |
commit | efaff195ba1fa55b6fe0b0b2435b81451387d241 (patch) | |
tree | 1923cd17053f841ed7e5035ace8f32637df29049 /test/Sema/format-strings.c | |
parent | c8dfe5ece04e683106eb96c58a2999f70b53ac21 (diff) |
For printf format string checking, add support for positional format strings.
Along the way, coelesce some of the diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/format-strings.c')
-rw-r--r-- | test/Sema/format-strings.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/Sema/format-strings.c b/test/Sema/format-strings.c index 191996004d..e92e17da08 100644 --- a/test/Sema/format-strings.c +++ b/test/Sema/format-strings.c @@ -221,3 +221,16 @@ void test_unicode_conversions(wchar_t *s) { printf("%S", "hello"); // expected-warning{{but the argument has type 'char *'}} } +// Mac OS X supports positional arguments in format strings. +// This is an IEEE extension (IEEE Std 1003.1). +// FIXME: This is probably not portable everywhere. +void test_positional_arguments() { + printf("%0$", (int)2); // expected-warning{{position arguments in format strings start counting at 1 (not 0)}} + printf("%1$d", (int) 2); // no-warning + printf("%1$d", (int) 2, 2); // expected-warning{{data argument not used by format string}} + printf("%1$d%1$f", (int) 2); // expected-warning{{conversion specifies type 'double' but the argument has type 'int'}} + printf("%1$2.2d", (int) 2); // no-warning + printf("%2$*1$.2d", (int) 2, (int) 3); // no-warning + printf("%2$*8$d", (int) 2, (int) 3); // expected-warning{{specified field width is missing a matching 'int' argument}} +} + |