blob: e770373a055bed61efed2de1801ff6c3a8b4c0aa [file] [log] [blame]
Fariborz Jahanian4ba4a5b2013-10-18 21:20:34 +00001// RUN: %clang_cc1 -Werror -Wformat-nonliteral -verify -fsyntax-only %s
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00002
3@class NSString;
4
5extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
6extern NSString *fa3 (NSString *) __attribute__((format_arg(1)));
7
Aaron Ballmanb7243382013-07-23 19:30:11 +00008extern void fc1 (const NSString *) __attribute__((format_arg)); // expected-error {{'format_arg' attribute takes one argument}}
9extern void fc2 (const NSString *) __attribute__((format_arg())); // expected-error {{'format_arg' attribute takes one argument}}
10extern void fc3 (const NSString *) __attribute__((format_arg(1, 2))); // expected-error {{'format_arg' attribute takes one argument}}
Fariborz Jahanianf1c25022009-05-20 17:41:43 +000011
Fariborz Jahanian4ba4a5b2013-10-18 21:20:34 +000012struct s1 { int i; } __attribute__((format_arg(1))); // expected-error {{'format_arg' attribute only applies to functions}}
13union u1 { int i; } __attribute__((format_arg(1))); // expected-error {{'format_arg' attribute only applies to functions}}
14enum e1 { E1V0 } __attribute__((format_arg(1))); // expected-error {{'format_arg' attribute only applies to functions}}
Fariborz Jahanianf1c25022009-05-20 17:41:43 +000015
16extern NSString *ff3 (const NSString *) __attribute__((format_arg(3-2)));
Douglas Gregord2472d42013-05-02 23:25:32 +000017extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{use of undeclared identifier 'foo'}}
Fariborz Jahanianf1c25022009-05-20 17:41:43 +000018
19/* format_arg formats must take and return a string. */
20extern NSString *fi0 (int) __attribute__((format_arg(1))); // expected-error {{format argument not a string type}}
21extern NSString *fi1 (NSString *) __attribute__((format_arg(1)));
22
23extern NSString *fi2 (NSString *) __attribute__((format_arg(1)));
24
25extern int fi3 (const NSString *) __attribute__((format_arg(1))); // expected-error {{function does not return NSString}}
26extern NSString *fi4 (const NSString *) __attribute__((format_arg(1)));
27extern NSString *fi5 (const NSString *) __attribute__((format_arg(1)));
Fariborz Jahanian4ba4a5b2013-10-18 21:20:34 +000028
29// rdar://15242010
30@interface NSString
31+ (id)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2)));
32@end
33
34@interface NSBundle
35- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName __attribute__ ((format_arg(1)));
36+ (NSBundle *)mainBundle;
37@end
38
39
40NSString* localizedFormat(NSString* string) __attribute__ ((format_arg(1)));
41
42int main()
43{
44 [NSString stringWithFormat:[[NSBundle mainBundle] localizedStringForKey:@"foo %d" value:@"bar %d" table:0], 42];
45
46 [NSString stringWithFormat:localizedFormat(@"foo %d"), 42];
47}