[llvm-bugs] [Bug 25149] New: __kindof type checking breaks sortedArrayUsingFunction: example in Apple docs, in Objective-C++ files.
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Oct 12 11:21:13 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=25149
Bug ID: 25149
Summary: __kindof type checking breaks
sortedArrayUsingFunction: example in Apple docs, in
Objective-C++ files.
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: nicolasweber at gmx.de
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
From
https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context:
:
"""
Given anArray (an array of NSNumber objects) and a comparison function of this
type:
NSInteger intSort(id num1, id num2, void *context)
{
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
A sorted version of anArray is created in this way:
NSArray *sortedArray; sortedArray = [anArray sortedArrayUsingFunction:intSort
context:NULL];
"""
Doing this results in a warning with the 10.11 SDK when used like so (which
quickly happens in practice when passing e.g. [myview subviews] as array):
#import <Foundation/Foundation.h>
NSInteger intSort(id num1, id num2, void* context) {
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}
id f(NSArray<__kindof NSNumber*>* anArray) {
NSArray* sortedArray =
[anArray sortedArrayUsingFunction:intSort context:NULL];
return sortedArray;
}
$ clang -c test.mm
test.mm:16:41: warning: incompatible pointer types sending 'NSInteger (*)(id,
id, void *)' to parameter of type 'NSInteger (* __nonnull)(__kindof NSNumber *
__nonnull, __kindof NSNumber * __nonnull, void * __nullable)'
[-Wincompatible-pointer-types]
[anArray sortedArrayUsingFunction:intSort context:NULL];
^~~~~~~
1 warning generated.
Is this intentional? Or should id typecheck as any __kindof? (works fine in .m
files but not in .mm)
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151012/0638ef2d/attachment.html>
More information about the llvm-bugs
mailing list