msg_280.c revision 1.6 1 /* $NetBSD: msg_280.c,v 1.6 2022/06/22 19:23:18 rillig Exp $ */
2 # 3 "msg_280.c"
3
4 // Test for message: comment /* %s */ must be outside function [280]
5
6 /* VARARGS */
7 void
8 varargs_ok(const char *str, ...)
9 {
10 (void)str;
11 }
12
13 /*
14 * In the following example, the comment looks misplaced, but lint does not
15 * warn about it.
16 *
17 * This is due to the implementation of the parser and the C grammar. When
18 * the parser sees the token T_LPAREN, it has to decide whether the following
19 * tokens will form a parameter type list or an identifier list. For that,
20 * it needs to look at the next token to see whether it is a T_NAME (in which
21 * case the T_LPAREN belongs to an id_list_lparen) or something else (in
22 * which case the T_LPAREN belongs to an abstract_decl_lparen). This token
23 * lookahead happens just before either of these grammar rules is reduced.
24 * During that reduction, the current declaration context switches from
25 * 'extern' to 'prototype argument', which makes this exact position the very
26 * last possible. Everything later would already be in the wrong context.
27 *
28 * As of cgram.y 1.360 from 2021-09-04, the implementation of these grammar
29 * rules is exactly the same, which makes it tempting to join them into a
30 * single rule.
31 */
32 void
33 varargs_bad_param(/* VARARGS */ const char *str, ...)
34 {
35 (void)str;
36 }
37
38 void
39 /* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
40 varargs_bad_ellipsis(const char *str, /* VARARGS */ ...)
41 {
42 (void)str;
43 }
44
45 void
46 varargs_bad_body(const char *str, ...)
47 {
48 /* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
49 /* VARARGS */
50 (void)str;
51 }
52
53 void
54 /* expect+1: warning: argument 'str' unused in function 'argsused_bad_body' [231] */
55 argsused_bad_body(const char *str)
56 {
57 /* expect+1: warning: comment ** ARGSUSED ** must be outside function [280] */
58 /* ARGSUSED */
59 }
60
61 void
62 printflike_bad_body(const char *fmt, ...)
63 {
64 /* expect+1: warning: comment ** PRINTFLIKE ** must be outside function [280] */
65 /* PRINTFLIKE */
66 (void)fmt;
67 }
68
69 void
70 scanflike_bad_body(const char *fmt, ...)
71 {
72 /* expect+1: warning: comment ** SCANFLIKE ** must be outside function [280] */
73 /* SCANFLIKE */
74 (void)fmt;
75 }
76