diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-07-19 18:10:08 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-07-19 18:10:08 +0000 |
commit | 48716663e421472cbd590af160a372bc490205e8 (patch) | |
tree | 06a1999a84e99c77cb55372edb040a39def39513 /test/SemaObjC/format-strings-objc.m | |
parent | ee7af50cc7999a2e5101da80bef0fdcff8c90b11 (diff) |
Don't crash checking a format string if one of the arguments is invalid.
Previously, we would ask for the SourceLocation of an argument even if
it were NULL (i.e. if Sema resulted in an ExprError trying to build it).
<rdar://problem/11890818>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaObjC/format-strings-objc.m')
-rw-r--r-- | test/SemaObjC/format-strings-objc.m | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/SemaObjC/format-strings-objc.m b/test/SemaObjC/format-strings-objc.m index 043cb5d8d2..c6f26e53b8 100644 --- a/test/SemaObjC/format-strings-objc.m +++ b/test/SemaObjC/format-strings-objc.m @@ -210,3 +210,20 @@ void test_nonBuiltinCFStrings() { CFStringCreateWithFormat(__CFStringMakeConstantString("%@"), 1); // expected-warning{{format specifies type 'id' but the argument has type 'int'}} } + +// Don't crash on an invalid argument expression. +// <rdar://problem/11890818> +@interface NSDictionary : NSObject +- (id)objectForKeyedSubscript:(id)key; +@end + +void testInvalidFormatArgument(NSDictionary *dict) { + NSLog(@"no specifiers", dict[CFSTR("abc")]); // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} + NSLog(@"%@", dict[CFSTR("abc")]); // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} + NSLog(@"%@ %@", dict[CFSTR("abc")]); // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} + + [Foo fooWithFormat:@"no specifiers", dict[CFSTR("abc")]]; // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} + [Foo fooWithFormat:@"%@", dict[CFSTR("abc")]]; // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} + [Foo fooWithFormat:@"%@ %@", dict[CFSTR("abc")]]; // expected-error{{indexing expression is invalid because subscript type 'CFStringRef' (aka 'const struct __CFString *') is not an integral or objective-C pointer type}} expected-warning{{more '%' conversions than data arguments}} +} + |