Home | History | Annotate | Line # | Download | only in lint1
      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 */
      9 void
     10 varargs_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  */
     34 void
     35 varargs_bad_param(/* VARARGS */ const char *str, ...)
     36 {
     37 	(void)str;
     38 }
     39 
     40 void
     41 /* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
     42 varargs_bad_ellipsis(const char *str, /* VARARGS */ ...)
     43 {
     44 	(void)str;
     45 }
     46 
     47 void
     48 varargs_bad_body(const char *str, ...)
     49 {
     50 	/* expect+1: warning: comment ** VARARGS ** must be outside function [280] */
     51 	/* VARARGS */
     52 	(void)str;
     53 }
     54 
     55 void
     56 /* expect+1: warning: parameter 'str' unused in function 'argsused_bad_body' [231] */
     57 argsused_bad_body(const char *str)
     58 {
     59 	/* expect+1: warning: comment ** ARGSUSED ** must be outside function [280] */
     60 	/* ARGSUSED */
     61 }
     62 
     63 void
     64 printflike_bad_body(const char *fmt, ...)
     65 {
     66 	/* expect+1: warning: comment ** PRINTFLIKE ** must be outside function [280] */
     67 	/* PRINTFLIKE */
     68 	(void)fmt;
     69 }
     70 
     71 void
     72 scanflike_bad_body(const char *fmt, ...)
     73 {
     74 	/* expect+1: warning: comment ** SCANFLIKE ** must be outside function [280] */
     75 	/* SCANFLIKE */
     76 	(void)fmt;
     77 }
     78