Debian Codegraph @

gcc/testsuite/objc.dg/attributes/method-format-1.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, October 2010. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall" } */
4 /* { dg-additional-options "-Wno-objc-root-class" } */
5
6 #include <objc/objc.h>
7 #include <stdlib.h>
8
9 @interface LogObject
10 {
11 Class isa;
12 }
13 + (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3)));
14 - (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3)));
15
16 + (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2)));
17 - (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2)));
18
19 /* Just make sure a missing or invalid attribute won't crash the compiler. */
20 - (void) log2: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2))); /* { dg-error "wrong" } */
21 + (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */
22 - (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */
23 + (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "does not refer to a variable argument list" } */
24 - (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "does not refer to a variable argument list" } */
25 @end
26
27 void test (LogObject *object)
28 {
29 [object log: 2 message: "attribute only applies to variadic functions"];
30 [object log: 2 message: "attribute %s only applies to variadic functions", "'format'"];
31 [object log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */
32
33 [object debug: "attribute only applies to variadic functions"];
34 [object debug: "attribute %s only applies to variadic functions", "'format'"];
35 [object debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */
36
37 [LogObject log: 2 message: "attribute only applies to variadic functions"];
38 [LogObject log: 2 message: "attribute %s only applies to variadic functions", "'format'"];
39 [LogObject log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */
40
41 [LogObject debug: "attribute only applies to variadic functions"];
42 [LogObject debug: "attribute %s only applies to variadic functions", "'format'"];
43 [LogObject debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "expects a matching" } */
44 }