<html>
<head>
<base href="http://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 --- - Declaring '+(instancetype) alloc __attribute__((unavailable("")));' forbids calling alloc on variables of Class type"
href="http://llvm.org/bugs/show_bug.cgi?id=20581">20581</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Declaring '+(instancetype) alloc __attribute__((unavailable("")));' forbids calling alloc on variables of Class type
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rsanchez.saez@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>I have an Objective-C singleton class for which I declare these:
@interface MySingleton : NSObject
+ (instancetype) sharedInstance;
+ (instancetype) alloc __attribute__((unavailable("call sharedInstance
instead")));
- (instancetype) init __attribute__((unavailable("call sharedInstance
instead")));
+ (instancetype) new __attribute__((unavailable("call sharedInstance
instead")));
@end
My implementation is as follows:
@implementation MySingleton
+ (instancetype)sharedInstance
{
static dispatch_once_t s_dispatchOnceToken;
static id s_sharedInstance = nil;
dispatch_once(&s_dispatchOnceToken, ^
{
s_sharedInstance = [[super alloc] initSharedInstance];
});
return s_sharedInstance;
}
- (instancetype)initSharedInstance
{
return [super init];
}
@end
All this works as expected.
However, I have a MySingleton instance method like this:
- (void)instanceMethod
{
Class unrelatedClass = [self getClassWithType:classType]; //classType
is a NSString. This method never returns the MySingleton class
id activity = [[unrelatedClass alloc] init];
}
which should compile fine, but the compiler wrongly says:
'alloc' is unavailable: call sharedInstance instead
This issue is present in both CLANG versions included on Xcode 6 Beta 5 and on
5.1.1.</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>