<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Objective C - compiler error using new within the implementation when init is marked with unavailable attribute"
   href="https://bugs.llvm.org/show_bug.cgi?id=40285">40285</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Objective C - compiler error using new within the implementation when init is marked with unavailable attribute
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jelin@microsoft.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21311" name="attach_21311" title="Repro test code.">attachment 21311</a> <a href="attachment.cgi?id=21311&action=edit" title="Repro test code.">[details]</a></span>
Repro test code.

The regression was introduced sometime between 340925 and 342523.

The following code used to compile fine in 340925, but now generate the error:

#import <Foundation/Foundation.h>

@interface Test : NSObject

- (nullable instancetype)init __attribute__((unavailable("Use the
sharedInstance singleton method instead.")));

+ (nullable instancetype)sharedInstance;

@end

@implementation Test

+ (nullable instancetype)sharedInstance {
    return [Test new];
}

@end


Compiled with:
clang -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk
-c test.m

Error message:
test.m:25:18: error: 'new' is unavailable: Use the sharedInstance
      singleton method instead.
    return [Test new];
                 ^
test.m:14:1: note: 'init' has been explicitly marked unavailable
      here
- (nullable instancetype)init __attribute__((unavailable("Use the shared...
^
1 error generated.</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>