r217543 - Objective-C. Accept 'nil' as indexing argument to
Argyrios Kyrtzidis
kyrtzidis at apple.com
Wed Sep 10 14:57:17 PDT 2014
Was it intentional to accept any ‘void *’ pointer, or did you want to just accept nil ?
If intentional, you should add a test case (e.g. pass a void* variable).
> On Sep 10, 2014, at 1:55 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>
> Author: fjahanian
> Date: Wed Sep 10 15:55:31 2014
> New Revision: 217543
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217543&view=rev
> Log:
> Objective-C. Accept 'nil' as indexing argument to
> dictionary literals since the API which implements
> them accepts it too. // rdar://18254621
>
> Modified:
> cfe/trunk/lib/Sema/SemaPseudoObject.cpp
> cfe/trunk/test/SemaObjC/objc-dictionary-literal.m
>
> Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=217543&r1=217542&r2=217543&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Wed Sep 10 15:55:31 2014
> @@ -1022,7 +1022,8 @@ Sema::ObjCSubscriptKind
> // If we don't have a class type in C++, there's no way we can get an
> // expression of integral or enumeration type.
> const RecordType *RecordTy = T->getAs<RecordType>();
> - if (!RecordTy && T->isObjCObjectPointerType())
> + if (!RecordTy &&
> + (T->isObjCObjectPointerType() || T->isVoidPointerType()))
> // All other scalar cases are assumed to be dictionary indexing which
> // caller handles, with diagnostics if needed.
> return OS_Dictionary;
>
> Modified: cfe/trunk/test/SemaObjC/objc-dictionary-literal.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-dictionary-literal.m?rev=217543&r1=217542&r2=217543&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaObjC/objc-dictionary-literal.m (original)
> +++ cfe/trunk/test/SemaObjC/objc-dictionary-literal.m Wed Sep 10 15:55:31 2014
> @@ -3,6 +3,8 @@
> // RUN: %clang_cc1 -fsyntax-only -triple i386-apple-macosx10.9.0 -fobjc-runtime=macosx-fragile-10.9.0 -fobjc-subscripting-legacy-runtime -verify %s
> // rdar://15363492
>
> +#define nil ((void *)0)
> +
> @interface NSNumber
> + (NSNumber *)numberWithChar:(char)value;
> + (NSNumber *)numberWithInt:(int)value;
> @@ -15,6 +17,7 @@ typedef long NSInteger;
> @interface NSDictionary
> + (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
> - (void)setObject:(id)object forKeyedSubscript:(id)key;
> +- (id)objectForKeyedSubscript:(id)key;
> @end
>
> @interface NSString<NSCopying>
> @@ -31,6 +34,13 @@ int main() {
>
> dict["name"] = @666; // expected-error {{indexing expression is invalid because subscript type 'char *' is not an Objective-C pointer}}
>
> + // rdar://18254621
> + [@{@"foo" : @"bar"} objectForKeyedSubscript:nil];
> + (void)@{@"foo" : @"bar"}[nil];
> +
> + [@{@"foo" : @"bar"} setObject:nil forKeyedSubscript:@"gorf"];
> + @{@"foo" : @"bar"}[nil] = @"gorf";
> +
> return 0;
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list