<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - __kindof type checking breaks sortedArrayUsingFunction: example in Apple docs, in Objective-C++ files."
href="https://llvm.org/bugs/show_bug.cgi?id=25149">25149</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__kindof type checking breaks sortedArrayUsingFunction: example in Apple docs, in Objective-C++ files.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nicolasweber@gmx.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>From
<a href="https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context">https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context</a>:
:
"""
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)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>