annotate gcc/testsuite/gcc.dg/darwin-cfstring-format-1.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Check CFString format extensions. */
kono
parents:
diff changeset
2 /* { dg-do compile { target *-*-darwin* } } */
kono
parents:
diff changeset
3 /* { dg-options "-Wall" } */
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 extern int printf (const char *fmt, ...);
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 typedef const struct __CFString * CFStringRef;
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 #ifdef __CONSTANT_CFSTRINGS__
kono
parents:
diff changeset
10 #define CFSTR(cStr) ((CFStringRef) __builtin___CFStringMakeConstantString ("" cStr ""))
kono
parents:
diff changeset
11 #else
kono
parents:
diff changeset
12 #error requires CFString
kono
parents:
diff changeset
13 #endif
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 int s1 (CFStringRef fmt, ...) __attribute__((format(CFString, 1, 2))) ; /* OK */
kono
parents:
diff changeset
16 int s2 (int a, CFStringRef fmt, ... ) __attribute__((format(__CFString__, 2, 3))) ; /* OK */
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 int s2a (int a, CFStringRef fmt, ... ) __attribute__((format(CFString, 2, 2))) ; /* { dg-error "format string argument follows the args to be formatted" } */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 int s3 (const char *fmt, ... ) __attribute__((format(__CFString__, 1, 2))) ; /* { dg-error "format argument should be a .CFString. reference but a string was found" } */
kono
parents:
diff changeset
21 int s4 (CFStringRef fmt, ... ) __attribute__((format(printf, 1, 2))) ; /* { dg-error "found a .CFStringRef.* but the format argument should be a string" } */
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 char *s5 (char dum, char *fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */
kono
parents:
diff changeset
24 CFStringRef s6 (CFStringRef dum, CFStringRef fmt1, ... ) __attribute__((format_arg(2))) ; /* OK */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 char *s7 (int dum, void *fmt1, ... ) __attribute__((format_arg(2))) ; /* { dg-error "format string argument is not a string type" } */
kono
parents:
diff changeset
27 int s8 (CFStringRef dum, CFStringRef fmt1, ... ) __attribute__((format_arg(2))) ; /* { dg-error "function does not return string type" } */
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 void foo (void)
kono
parents:
diff changeset
30 {
kono
parents:
diff changeset
31 CFStringRef notchk = CFSTR ("here is an unchecked %d %s string");
kono
parents:
diff changeset
32 s1 (notchk, 5, 6, 7);
kono
parents:
diff changeset
33 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." } */
kono
parents:
diff changeset
34 /* { dg-warning "too many arguments for format" "" { target *-*-* } .-1 } */
kono
parents:
diff changeset
35 printf(s5 (1, "and so is this %d %d %s", 3, 4, "hey", 6), 5, 6, 12);/* { dg-warning "format .%s. expects argument of type .char .., but argument 4 has type .int." } */
kono
parents:
diff changeset
36 }