diff options
author | Nico Weber <nicolasweber@gmx.de> | 2012-01-31 01:43:25 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2012-01-31 01:43:25 +0000 |
commit | 496cdc2cb75b9910eeee089610c98a48391076ee (patch) | |
tree | 2345ceb8cfd8203c73f2a5153c0b8f624e8bb31e /clang/test/SemaObjC/format-strings-objc.m | |
parent | 6b68c98f7d52b01b8a55896632a334b554467bad (diff) | |
download | bcm5719-llvm-496cdc2cb75b9910eeee089610c98a48391076ee.tar.gz bcm5719-llvm-496cdc2cb75b9910eeee089610c98a48391076ee.zip |
Let %S, %ls, %C match 16bit types in NSStrings.
As discussed at http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120130/052200.html
llvm-svn: 149325
Diffstat (limited to 'clang/test/SemaObjC/format-strings-objc.m')
-rw-r--r-- | clang/test/SemaObjC/format-strings-objc.m | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/format-strings-objc.m b/clang/test/SemaObjC/format-strings-objc.m index 5ab4d8bf3ba..24330006df9 100644 --- a/clang/test/SemaObjC/format-strings-objc.m +++ b/clang/test/SemaObjC/format-strings-objc.m @@ -115,3 +115,35 @@ extern NSString *GetLocalizedString(NSString *str); void check_NSLocalizedString() { [Foo fooWithFormat:NSLocalizedString(@"format"), @"arg"]; // no-warning } + +typedef __WCHAR_TYPE__ wchar_t; + + +// Test that %S, %C, %ls check for 16 bit types in ObjC strings, as described at +// http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265 + +void test_percent_S() { + const unsigned short data[] = { 'a', 'b', 0 }; + const unsigned short* ptr = data; + NSLog(@"%S", ptr); // no-warning + + const wchar_t* wchar_ptr = L"ab"; + NSLog(@"%S", wchar_ptr); // expected-warning{{format specifies type 'const unsigned short *' but the argument has type 'const wchar_t *'}} +} + +void test_percent_ls() { + const unsigned short data[] = { 'a', 'b', 0 }; + const unsigned short* ptr = data; + NSLog(@"%ls", ptr); // no-warning + + const wchar_t* wchar_ptr = L"ab"; + NSLog(@"%ls", wchar_ptr); // expected-warning{{format specifies type 'const unsigned short *' but the argument has type 'const wchar_t *'}} +} + +void test_percent_C() { + const unsigned short data = 'a'; + NSLog(@"%C", data); // no-warning + + const wchar_t wchar_data = L'a'; + NSLog(@"%C", wchar_data); // expected-warning{{format specifies type 'unsigned short' but the argument has type 'wchar_t'}} +} |