llvm-project/clang/test/SemaObjC/call-unavailable-init-in-self.m
Aaron Ballman 22db4824b9 Use functions with prototypes when appropriate; NFC
A significant number of our tests in C accidentally use functions
without prototypes. This patch converts the function signatures to have
a prototype for the situations where the test is not specific to K&R C
declarations. e.g.,

  void func();

becomes

  void func(void);

This is the third batch of tests being updated (there are a significant
number of other tests left to be updated).
2022-02-07 09:25:01 -05:00

87 lines
1.5 KiB
Objective-C

// RUN: %clang_cc1 -x objective-c -verify -fobjc-arc %s
@interface NSObject
+ (instancetype)new;
+ (instancetype)alloc;
- (void)declaredInSuper;
@end
@interface NSObject (Category)
- (void)declaredInSuperCategory;
@end
@interface Sub: NSObject
- (instancetype)init __attribute__((unavailable)); // expected-note 4 {{'init' has been explicitly marked unavailable here}}
- (void)notImplemented __attribute__((unavailable));
- (void)declaredInSuper __attribute__((unavailable));
- (void)declaredInSuperCategory __attribute__((unavailable));
@end
@implementation Sub
+ (Sub *)create {
return [[self alloc] init];
}
+ (Sub *)create2 {
return [self new];
}
+ (Sub *)create3 {
return [Sub new];
}
- (instancetype) init {
return self;
}
- (void)reportUseOfUnimplemented {
[self notImplemented];
}
- (void)allowSuperCallUsingSelf {
[self declaredInSuper];
[[Sub alloc] declaredInSuper];
[self declaredInSuperCategory];
[[Sub alloc] declaredInSuperCategory];
}
@end
@interface SubClassContext: Sub
@end
@implementation SubClassContext
- (void)subClassContext {
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}}
(void)[Sub new]; // expected-error {{'new' is unavailable}}
}
@end
void unrelatedContext(void) {
(void)[[Sub alloc] init]; // expected-error {{'init' is unavailable}}
(void)[Sub new]; // expected-error {{'new' is unavailable}}
}
@interface X @end
@interface X (Foo)
-(void)meth __attribute__((unavailable));
@end
@implementation X (Foo)
-(void)meth {}
-(void)call_it { [self meth]; }
@end