]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/format-arg-attribute.m
Vendor import of clang release_34 branch r197841 (effectively, 3.4 RC3):
[FreeBSD/FreeBSD.git] / test / SemaObjC / format-arg-attribute.m
1 // RUN: %clang_cc1 -Werror -Wformat-nonliteral -verify -fsyntax-only %s
2
3 @class NSString;
4
5 extern NSString *fa2 (const NSString *) __attribute__((format_arg(1)));
6 extern NSString *fa3 (NSString *) __attribute__((format_arg(1)));
7
8 extern void fc1 (const NSString *) __attribute__((format_arg));  // expected-error {{'format_arg' attribute takes one argument}}
9 extern void fc2 (const NSString *) __attribute__((format_arg())); // expected-error {{'format_arg' attribute takes one argument}}
10 extern void fc3 (const NSString *) __attribute__((format_arg(1, 2))); // expected-error {{'format_arg' attribute takes one argument}}
11
12 struct s1 { int i; } __attribute__((format_arg(1)));  // expected-error {{'format_arg' attribute only applies to functions}}
13 union u1 { int i; } __attribute__((format_arg(1)));  // expected-error {{'format_arg' attribute only applies to functions}}
14 enum e1 { E1V0 } __attribute__((format_arg(1))); // expected-error {{'format_arg' attribute only applies to functions}}
15
16 extern NSString *ff3 (const NSString *) __attribute__((format_arg(3-2)));
17 extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{use of undeclared identifier 'foo'}}
18
19 /* format_arg formats must take and return a string.  */
20 extern NSString *fi0 (int) __attribute__((format_arg(1)));  // expected-error {{format argument not a string type}}
21 extern NSString *fi1 (NSString *) __attribute__((format_arg(1))); 
22
23 extern NSString *fi2 (NSString *) __attribute__((format_arg(1))); 
24
25 extern int fi3 (const NSString *) __attribute__((format_arg(1)));  // expected-error {{function does not return NSString}}
26 extern NSString *fi4 (const NSString *) __attribute__((format_arg(1))); 
27 extern NSString *fi5 (const NSString *) __attribute__((format_arg(1))); 
28
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
40 NSString* localizedFormat(NSString* string) __attribute__ ((format_arg(1)));
41
42 int 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 }