lex_comment.c revision 1.2 1 /* $NetBSD: lex_comment.c,v 1.2 2024/10/04 11:24:13 rillig Exp $ */
2 # 3 "lex_comment.c"
3
4 /*
5 * Tests for comments, including lint-style comments that
6 * suppress a single diagnostic.
7 */
8
9 /* lint1-extra-flags: -X 351 -aa */
10
11 signed char s8;
12 signed long long s64;
13
14 // A "LINTED" comment suppresses a single warning until the end of the next
15 // statement.
16 void
17 lint_comment(void)
18 {
19 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
20 s8 = s64;
21
22 /* LINTED 132 */
23 s8 = s64;
24
25 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
26 s8 = s64;
27
28 /* LINTED 132 "comment" */
29 s8 = s64;
30
31 /* LINTED 132 */
32 {
33 }
34 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
35 s8 = s64;
36
37 /* LINTED 132 */
38 {
39 s8 = s64;
40 }
41 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
42 s8 = s64;
43
44 if (s8 == 0)
45 ;
46 /* LINTED 132 */
47 s8 = s64;
48
49 if (s8 == 0) {
50 }
51 /* LINTED 132 */
52 s8 = s64;
53
54 if (s8 == 0)
55 ;
56 else
57 ;
58 /* LINTED 132 */
59 s8 = s64;
60
61 if (s8 == 0) {
62 } else {
63 }
64 /* LINTED 132 */
65 s8 = s64;
66
67 if (s8 == 0) {
68 } else if (s8 == 1)
69 ;
70 /* LINTED 132 */
71 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
72 s8 = s64;
73
74 if (s8 == 0) {
75 } else if (s8 == 1) {
76 }
77 /* LINTED 132 */
78 /* expect+1: warning: conversion from 'long long' to 'signed char' may lose accuracy [132] */
79 s8 = s64;
80 }
81
82
83 /*
84 * Before lex.c 1.41 from 2021-06-19, lint ran into an endless loop when it
85 * saw an unclosed comment at the end of the translation unit. In practice
86 * this was not relevant since the translation unit always comes from the C
87 * preprocessor, which always emits a well-formed token sequence.
88 */
89
90 /* expect+2: error: unterminated comment [256] */
91 /* unclosed comment
92