| 1 |
/* Check NSString format extensions. */ |
| 2 |
/* { dg-do compile { target *-*-darwin* } } */ |
| 3 |
/* { dg-skip-if "" { *-*-* } { "-fgnu-runtime" } { "" } } */ |
| 4 |
/* { dg-options "-Wall" } */ |
| 5 |
|
| 6 |
extern int printf (const char *fmt, ...); |
| 7 |
|
| 8 |
#ifndef __CONSTANT_CFSTRINGS__ |
| 9 |
#error requires CFString |
| 10 |
#endif |
| 11 |
|
| 12 |
typedef const struct __CFString * CFStringRef; |
| 13 |
@class NSString; |
| 14 |
|
| 15 |
int s1 (NSString *fmt, ...) __attribute__((format(NSString, 1, 2))) ; /* OK */ |
| 16 |
/* A CFString can represent an NSString. */ |
| 17 |
int s1a (CFStringRef fmt, ...) __attribute__((format(NSString, 1, 2))) ; /* OK */ |
| 18 |
/* But... it is possible that a CFString format might imply functionality that |
| 19 |
is not present in objective-c. */ |
| 20 |
int s1b (NSString *fmt, ...) __attribute__((format(CFString, 1, 2))) ; /* { dg-error "format argument should be a .CFString. reference" } */ |
| 21 |
|
| 22 |
int s2 (int a, NSString *fmt, ... ) __attribute__((format(__NSString__, 2, 3))) ; /* OK */ |
| 23 |
|
| 24 |
int s2a (int a, NSString *fmt, ... ) __attribute__((format(NSString, 2, 2))) ; /* { dg-error ".format. attribute argument 3 value .2. does not refer to a variable argument list" } */ |
| 25 |
|
| 26 |
int s3 (const char *fmt, ... ) __attribute__((format(__NSString__, 1, 2))) ; /* { dg-error "format argument should be a .NSString. reference but a string was found" } */ |
| 27 |
int s4 (NSString *fmt, ... ) __attribute__((format(printf, 1, 2))) ; /* { dg-error "found a .NSString. reference but the format argument should be a string" } */ |
| 28 |
|
| 29 |
char *s5 (char dum, char *fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */ |
| 30 |
NSString *s6 (NSString *dum, NSString *fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */ |
| 31 |
|
| 32 |
char *s7 (int dum, void *fmt1, ... ) __attribute__((format_arg(2))) ; /* { dg-error ".format_arg. attribute argument value .2. refers to parameter type .void \\\*." } */ |
| 33 |
int s8 (NSString *dum, NSString *fmt1, ... ) __attribute__((format_arg(2))) ; /* { dg-error "function does not return string type" } */ |
| 34 |
|
| 35 |
char *s9 (int dum, char *fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */ |
| 36 |
NSString *s10 (int dum, NSString *fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */ |
| 37 |
|
| 38 |
void foo (void) |
| 39 |
{ |
| 40 |
s1 (@"format not checked %d %s", 3, 4); |
| 41 |
printf("this one is checked %d %s", 3, 4, 5); /* { dg-warning "format '%s' expects argument of type 'char .', but argument 3 has type 'int'" } */ |
| 42 |
/* { dg-warning "too many arguments for format" "" { target *-*-* } .-1 } */ |
| 43 |
printf(s9 (1, "and so is this %d %d %s", 3, 4), 5, 6, 12); /* { dg-warning "format '%s' expects argument of type 'char .', but argument 4 has type 'int'" } */ |
| 44 |
} |