1*039b0100Srillig /* $NetBSD: msg_280.c,v 1.9 2023/08/02 18:51:25 rillig Exp $ */
2a0a15c14Srillig # 3 "msg_280.c"
3a0a15c14Srillig
440a9b8fdSrillig // Test for message: comment /* %s */ must be outside function [280]
5a0a15c14Srillig
6e6298b92Srillig /* lint1-extra-flags: -X 351 */
7e6298b92Srillig
8dea6b66dSrillig /* VARARGS */
9dea6b66dSrillig void
varargs_ok(const char * str,...)10dea6b66dSrillig varargs_ok(const char *str, ...)
11dea6b66dSrillig {
12dea6b66dSrillig (void)str;
13dea6b66dSrillig }
14dea6b66dSrillig
152e040a70Srillig /*
162e040a70Srillig * In the following example, the comment looks misplaced, but lint does not
172e040a70Srillig * warn about it.
182e040a70Srillig *
192e040a70Srillig * This is due to the implementation of the parser and the C grammar. When
202e040a70Srillig * the parser sees the token T_LPAREN, it has to decide whether the following
212e040a70Srillig * tokens will form a parameter type list or an identifier list. For that,
222e040a70Srillig * it needs to look at the next token to see whether it is a T_NAME (in which
232e040a70Srillig * case the T_LPAREN belongs to an id_list_lparen) or something else (in
242e040a70Srillig * which case the T_LPAREN belongs to an abstract_decl_lparen). This token
252e040a70Srillig * lookahead happens just before either of these grammar rules is reduced.
262e040a70Srillig * During that reduction, the current declaration context switches from
27*039b0100Srillig * DLK_EXTERN to DLK_PROTO_PARAMS, which makes this exact position the very
282e040a70Srillig * last possible. Everything later would already be in the wrong context.
292e040a70Srillig *
302e040a70Srillig * As of cgram.y 1.360 from 2021-09-04, the implementation of these grammar
312e040a70Srillig * rules is exactly the same, which makes it tempting to join them into a
322e040a70Srillig * single rule.
332e040a70Srillig */
34dea6b66dSrillig void
varargs_bad_param(const char * str,...)35dea6b66dSrillig varargs_bad_param(/* VARARGS */ const char *str, ...)
36dea6b66dSrillig {
37dea6b66dSrillig (void)str;
38dea6b66dSrillig }
39dea6b66dSrillig
40dea6b66dSrillig void
4140a9b8fdSrillig /* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
varargs_bad_ellipsis(const char * str,...)42dea6b66dSrillig varargs_bad_ellipsis(const char *str, /* VARARGS */ ...)
43dea6b66dSrillig {
44dea6b66dSrillig (void)str;
45dea6b66dSrillig }
46dea6b66dSrillig
47dea6b66dSrillig void
varargs_bad_body(const char * str,...)48dea6b66dSrillig varargs_bad_body(const char *str, ...)
49dea6b66dSrillig {
5040a9b8fdSrillig /* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
51dea6b66dSrillig /* VARARGS */
52dea6b66dSrillig (void)str;
53dea6b66dSrillig }
54dea6b66dSrillig
55dea6b66dSrillig void
56ea332265Srillig /* expect+1: warning: parameter 'str' unused in function 'argsused_bad_body' [231] */
argsused_bad_body(const char * str)57dea6b66dSrillig argsused_bad_body(const char *str)
58dea6b66dSrillig {
5940a9b8fdSrillig /* expect+1: warning: comment ** ARGSUSED ** must be outside function [280] */
60dea6b66dSrillig /* ARGSUSED */
61dea6b66dSrillig }
62dea6b66dSrillig
63dea6b66dSrillig void
printflike_bad_body(const char * fmt,...)64dea6b66dSrillig printflike_bad_body(const char *fmt, ...)
65dea6b66dSrillig {
6640a9b8fdSrillig /* expect+1: warning: comment ** PRINTFLIKE ** must be outside function [280] */
67dea6b66dSrillig /* PRINTFLIKE */
68dea6b66dSrillig (void)fmt;
69dea6b66dSrillig }
70dea6b66dSrillig
71dea6b66dSrillig void
scanflike_bad_body(const char * fmt,...)72dea6b66dSrillig scanflike_bad_body(const char *fmt, ...)
73dea6b66dSrillig {
7440a9b8fdSrillig /* expect+1: warning: comment ** SCANFLIKE ** must be outside function [280] */
75dea6b66dSrillig /* SCANFLIKE */
76dea6b66dSrillig (void)fmt;
77dea6b66dSrillig }
78