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