[LLVMbugs] [Bug 20581] New: Declaring '+(instancetype) alloc __attribute__((unavailable(""))); ' forbids calling alloc on variables of Class type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 7 15:30:32 PDT 2014


            Bug ID: 20581
           Summary: Declaring '+(instancetype) alloc
                    __attribute__((unavailable("")));' forbids calling
                    alloc on variables of Class type
           Product: new-bugs
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: rsanchez.saez at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I have an Objective-C singleton class for which I declare these:

@interface MySingleton : NSObject

+ (instancetype) sharedInstance;
+ (instancetype) alloc __attribute__((unavailable("call sharedInstance
- (instancetype) init __attribute__((unavailable("call sharedInstance
+ (instancetype) new __attribute__((unavailable("call sharedInstance


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];                                        


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

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/20140807/6b4be49d/attachment.html>

More information about the llvm-bugs mailing list