| 1 |
// RUN: %clang_cc1 -verify -fsyntax-only %s |
| 2 |
|
| 3 |
@interface NSString |
| 4 |
+(instancetype)stringWithCString:(const char *)cstr __attribute__((format_arg(1))); |
| 5 |
-(instancetype)initWithString:(NSString *)str __attribute__((format_arg(1))); |
| 6 |
|
| 7 |
+(instancetype _Nonnull)nonNullableString:(NSString *)str __attribute__((format_arg(1))); |
| 8 |
+(instancetype _Nullable)nullableString:(NSString *)str __attribute__((format_arg(1))); |
| 9 |
@end |
| 10 |
|
| 11 |
@protocol MaybeString |
| 12 |
-(instancetype)maybeString:(const char *)cstr __attribute__((format_arg(1))); // expected-error {{function does not return string type}} |
| 13 |
@end |
| 14 |
|
| 15 |
@class NSAttributedString; |
| 16 |
|
| 17 |
extern NSString *fa2 (const NSString *) __attribute__((format_arg(1))); |
| 18 |
extern NSString *fa3 (NSString *) __attribute__((format_arg(1))); |
| 19 |
|
| 20 |
extern void fc1 (const NSString *) __attribute__((format_arg)); // expected-error {{'format_arg' attribute takes one argument}} |
| 21 |
extern void fc2 (const NSString *) __attribute__((format_arg())); // expected-error {{'format_arg' attribute takes one argument}} |
| 22 |
extern void fc3 (const NSString *) __attribute__((format_arg(1, 2))); // expected-error {{'format_arg' attribute takes one argument}} |
| 23 |
|
| 24 |
struct s1 { int i; } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to Objective-C methods and non-K&R-style functions}} |
| 25 |
union u1 { int i; } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to}} |
| 26 |
enum e1 { E1V0 } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to}} |
| 27 |
|
| 28 |
extern NSString *ff3 (const NSString *) __attribute__((format_arg(3-2))); |
| 29 |
extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{use of undeclared identifier 'foo'}} |
| 30 |
|
| 31 |
/* format_arg formats must take and return a string. */ |
| 32 |
extern NSString *fi0 (int) __attribute__((format_arg(1))); // expected-error {{format argument not a string type}} |
| 33 |
extern NSString *fi1 (NSString *) __attribute__((format_arg(1))); |
| 34 |
|
| 35 |
extern NSString *fi2 (NSString *) __attribute__((format_arg(1))); |
| 36 |
|
| 37 |
extern int fi3 (const NSString *) __attribute__((format_arg(1))); // expected-error {{function does not return NSString}} |
| 38 |
extern NSString *fi4 (const NSString *) __attribute__((format_arg(1))); |
| 39 |
extern NSString *fi5 (const NSString *) __attribute__((format_arg(1))); |
| 40 |
|
| 41 |
extern NSAttributedString *fattrs (const NSString *) __attribute__((format_arg(1))); |