annotate gcc/testsuite/gcc.dg/format/proto.c @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 /* PR c/93812 - ICE on redeclaration of an attribute format function without
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 protoype
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 It's not clear that attribute format should be accepted on functions
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 without a prototype. If it's decided that it shouldn't be the tests
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 here will need to be adjusted.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 { dg-do compile }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 { dg-options "-Wall" } */
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 #define FMT(n1, n2) __attribute__((__format__(__printf__, n1, n2)))
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 // Exercise function declarations.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 FMT (1, 2) void print1 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 FMT (2, 3) void print2 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 void print2 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17 FMT (3, 4) void print3 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 FMT (3, 4) void print3 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 FMT (1, 2) void print4 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 void print4 (void); // { dg-warning "'format' attribute cannot be applied to a function that does not take variable arguments" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 void print5 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 FMT (1, 2) void print5 (void); // { dg-warning "\\\[-Wattributes" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 FMT (1, 2) void print6 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 void print6 (const char*, ...); // { dg-error "conflicting types" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 void print7 (const char*, ...);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 FMT (1, 2) void print7 (); // { dg-error "conflicting types" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 // Exercise function calls.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 void test_print (void)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36 print1 ("%i %s", 123, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 print1 ("%s %i", 123, 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 print2 (0, "%s %i", "", 123);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 print2 (1, "%i %s", "", 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 print3 (0, 1, "%s %i", "", 123);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 print3 (1, 2, "%i %s", "", 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 // Just verify there's no ICE.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 print4 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 print5 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 print6 ("%i %s", 123, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 // Exercise declarations of pointers to functions.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 FMT (1, 2) void (*pfprint1)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 FMT (2, 3) void (*pfprint2)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 void (*pfprint2)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 FMT (3, 4) void (*pfprint3)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 FMT (3, 4) void (*pfprint3)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 FMT (1, 2) void (*pfprint4)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 void (*pfprint4)(void); // { dg-warning "'format' attribute cannot be applied to a function that does not take variable arguments" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 void (*pfprint5)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 FMT (1, 2) void (*pfprint5)(void); // { dg-warning "\\\[-Wattributes" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 FMT (1, 2) void (*pfprint6)();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 void (*pfprint6)(const char*, ...); // { dg-error "conflicting types" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 void (*pfprint7)(const char*, ...);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 FMT (1, 2) void (*pfprint7)(); // { dg-error "conflicting types" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73 // Exercise calls via function pointers.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 void test_pfprint (void)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 pfprint1 ("%i %s", 123, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 pfprint1 ("%s %i", 123, 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 pfprint2 (0, "%s %i", "", 123);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 pfprint2 (1, "%i %s", "", 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 pfprint3 (0, 1, "%s %i", "", 123);
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 pfprint3 (1, 2, "%i %s", "", 123); // { dg-warning "\\\[-Wformat" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 // Just verify there's no ICE.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 pfprint4 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 pfprint5 ();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 pfprint6 ("%i %s", 123, "");
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 }