1 /* Test for GCC internal format directives.
3 { dg-options "-std=gnu99 -Wformat" } */
5 /* Magic identifiers must be set before the attribute is used. */
7 typedef long long __gcc_host_wide_int__
;
9 typedef struct location_s
16 typedef union tree_node
*tree
;
18 /* Define gimple as a dummy type. The typedef must be provided for
19 the C test to find the symbol. */
20 typedef struct gimple gimple
;
22 /* Likewise for gimple. */
23 typedef struct cgraph_node cgraph_node
;
25 /* Likewise for diagnostic_event_id_t. */
26 typedef struct diagnostic_event_id_t diagnostic_event_id_t
;
28 #define FORMAT(kind) __attribute__ ((format (__gcc_## kind ##__, 1, 2)))
30 void diag (const char*, ...) FORMAT (diag
);
31 void cdiag (const char*, ...) FORMAT (cdiag
);
32 void tdiag (const char*, ...) FORMAT (tdiag
);
33 void cxxdiag (const char*, ...) FORMAT (cxxdiag
);
34 void dump (const char*, ...) FORMAT (dump_printf
);
36 void test_diag (tree t
, gimple
*gc
, diagnostic_event_id_t
*event_id_ptr
)
38 diag ("%<"); /* { dg-warning "unterminated quoting directive" } */
39 diag ("%>"); /* { dg-warning "unmatched quoting directive " } */
40 diag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */
42 diag ("%G", gc
); /* { dg-warning "format" } */
43 diag ("%K", t
); /* { dg-warning "format" } */
44 diag ("%@", event_id_ptr
);
46 diag ("%R"); /* { dg-warning "unmatched color reset directive" } */
47 diag ("%r", ""); /* { dg-warning "unterminated color directive" } */
48 diag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */
50 diag ("%r%r%R", "", "");
51 diag ("%r%R%r%R", "", "");
53 diag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */
54 diag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */
55 diag ("%<%r%R%>", "");
58 void test_cdiag (tree t
, gimple
*gc
)
60 cdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */
61 cdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */
62 cdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */
64 cdiag ("%D", t
); /* { dg-warning ".D. conversion used unquoted" } */
66 cdiag ("%F", t
); /* { dg-warning ".F. conversion used unquoted" } */
67 cdiag ("%G", gc
); /* { dg-warning "format" } */
68 cdiag ("%K", t
); /* { dg-warning "format" } */
70 cdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */
71 cdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */
72 cdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */
74 cdiag ("%r%r%R", "", "");
75 cdiag ("%r%R%r%R", "", "");
77 cdiag ("%T", t
); /* { dg-warning ".T. conversion used unquoted" } */
78 cdiag ("%V", t
); /* { dg-warning ".V. conversion used unquoted" } */
83 cdiag ("%<%G%>", gc
); /* { dg-warning "format" } */
84 cdiag ("%<%K%>", t
); /* { dg-warning "format" } */
86 cdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */
87 cdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */
88 cdiag ("%<%r%R%>", "");
93 cdiag ("%<%qD%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
94 cdiag ("%<%qE%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
95 cdiag ("%<%qT%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
98 void test_tdiag (tree t
, gimple
*gc
)
100 tdiag ("%<"); /* { dg-warning "unterminated quoting directive" } */
101 tdiag ("%>"); /* { dg-warning "unmatched quoting directive " } */
102 tdiag ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */
104 tdiag ("%D", t
); /* { dg-warning ".D. conversion used unquoted" } */
106 tdiag ("%G", gc
); /* { dg-warning "format" } */
107 tdiag ("%K", t
); /* { dg-warning "format" } */
109 tdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */
110 tdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */
111 tdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */
114 tdiag ("%r%r%R", "", "");
115 tdiag ("%r%R%r%R", "", "");
117 tdiag ("%T", t
); /* { dg-warning ".T. conversion used unquoted" } */
121 tdiag ("%<%G%>", gc
); /* { dg-warning "format" } */
122 tdiag ("%<%K%>", t
); /* { dg-warning "format" } */
124 tdiag ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */
125 tdiag ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */
126 tdiag ("%<%r%R%>", "");
130 tdiag ("%<%qD%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
131 tdiag ("%<%qE%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
132 tdiag ("%<%qT%>", t
); /* { dg-warning ".q. flag used within a quoted sequence" } */
135 void test_cxxdiag (tree t
, gimple
*gc
)
137 cxxdiag ("%A", t
); /* { dg-warning ".A. conversion used unquoted" } */
138 cxxdiag ("%D", t
); /* { dg-warning ".D. conversion used unquoted" } */
140 cxxdiag ("%F", t
); /* { dg-warning ".F. conversion used unquoted" } */
141 cxxdiag ("%G", gc
); /* { dg-warning "format" } */
142 cxxdiag ("%K", t
); /* { dg-warning "format" } */
144 cxxdiag ("%R"); /* { dg-warning "unmatched color reset directive" } */
145 cxxdiag ("%r", ""); /* { dg-warning "unterminated color directive" } */
146 cxxdiag ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */
147 cxxdiag ("%r%R", "");
148 cxxdiag ("%r%R", "");
149 cxxdiag ("%r%r%R", "", "");
150 cxxdiag ("%r%R%r%R", "", "");
152 cxxdiag ("%S", t
); /* { dg-warning ".S. conversion used unquoted" } */
153 cxxdiag ("%T", t
); /* { dg-warning ".T. conversion used unquoted" } */
154 cxxdiag ("%V", t
); /* { dg-warning ".V. conversion used unquoted" } */
155 cxxdiag ("%X", t
); /* { dg-warning ".X. conversion used unquoted" } */
157 cxxdiag ("%<%A%>", t
);
158 cxxdiag ("%<%D%>", t
);
159 cxxdiag ("%<%E%>", t
);
160 cxxdiag ("%<%F%>", t
);
161 cxxdiag ("%<%R%>"); /* { dg-warning "unmatched color reset" } */
162 cxxdiag ("%<%r%R%>", "");
163 cxxdiag ("%<%S%>", t
);
164 cxxdiag ("%<%T%>", t
);
165 cxxdiag ("%<%V%>", t
);
166 cxxdiag ("%<%X%>", t
);
169 void test_dump (tree t
, gimple
*stmt
, cgraph_node
*node
)
171 dump ("%<"); /* { dg-warning "unterminated quoting directive" } */
172 dump ("%>"); /* { dg-warning "unmatched quoting directive " } */
173 dump ("%<foo%<bar%>%>"); /* { dg-warning "nested quoting directive" } */
175 dump ("%R"); /* { dg-warning "unmatched color reset directive" } */
176 dump ("%r", ""); /* { dg-warning "unterminated color directive" } */
177 dump ("%r%r", "", ""); /* { dg-warning "unterminated color directive" } */
179 dump ("%r%r%R", "", "");
180 dump ("%r%R%r%R", "", "");
182 dump ("%<%R%>"); /* { dg-warning "unmatched color reset directive" } */
183 dump ("%<%r%>", ""); /* { dg-warning "unterminated color directive" } */
184 dump ("%<%r%R%>", "");
191 dump ("%4.2f", 1.0); /* { dg-warning "format" } */