Annotation of src/usr.bin/xlint/lint1/err.c, Revision 1.158
1.158 ! rillig 1: /* $NetBSD: err.c,v 1.157 2022/04/02 21:47:04 rillig Exp $ */
1.2 cgd 2:
1.1 cgd 3: /*
4: * Copyright (c) 1994, 1995 Jochen Pohl
5: * All Rights Reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Jochen Pohl for
18: * The NetBSD Project.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
1.27 jmc 34: #if HAVE_NBTOOL_CONFIG_H
35: #include "nbtool_config.h"
36: #endif
37:
1.10 christos 38: #include <sys/cdefs.h>
1.17 tv 39: #if defined(__RCSID) && !defined(lint)
1.158 ! rillig 40: __RCSID("$NetBSD: err.c,v 1.157 2022/04/02 21:47:04 rillig Exp $");
1.1 cgd 41: #endif
42:
1.12 christos 43: #include <sys/types.h>
1.55 rillig 44: #include <stdarg.h>
1.1 cgd 45: #include <stdlib.h>
46:
47: #include "lint1.h"
48:
1.12 christos 49: /* number of errors found */
50: int nerr;
51:
52: /* number of syntax errors */
53: int sytxerr;
54:
55:
1.112 rillig 56: const char *const msgs[] = {
1.46 christos 57: "empty declaration", /* 0 */
1.74 rillig 58: "old style declaration; add 'int'", /* 1 */
1.1 cgd 59: "empty declaration", /* 2 */
1.73 rillig 60: "'%s' declared in argument declaration list", /* 3 */
1.1 cgd 61: "illegal type combination", /* 4 */
62: "modifying typedef with '%s'; only qualifiers allowed", /* 5 */
63: "use 'double' instead of 'long float'", /* 6 */
64: "only one storage class allowed", /* 7 */
65: "illegal storage class", /* 8 */
66: "only register valid as formal parameter storage class", /* 9 */
67: "duplicate '%s'", /* 10 */
68: "bit-field initializer out of range", /* 11 */
69: "compiler takes size of function", /* 12 */
70: "incomplete enum type: %s", /* 13 */
1.157 rillig 71: "", /* 14 */
1.154 rillig 72: "function returns illegal type '%s'", /* 15 */
1.1 cgd 73: "array of function is illegal", /* 16 */
74: "null dimension", /* 17 */
75: "illegal use of 'void'", /* 18 */
1.74 rillig 76: "void type for '%s'", /* 19 */
1.30 christos 77: "negative array dimension (%d)", /* 20 */
1.1 cgd 78: "redeclaration of formal parameter %s", /* 21 */
79: "incomplete or misplaced function definition", /* 22 */
1.128 rillig 80: "undefined label '%s'", /* 23 */
1.1 cgd 81: "cannot initialize function: %s", /* 24 */
82: "cannot initialize typedef: %s", /* 25 */
83: "cannot initialize extern declaration: %s", /* 26 */
84: "redeclaration of %s", /* 27 */
85: "redefinition of %s", /* 28 */
86: "previously declared extern, becomes static: %s", /* 29 */
87: "redeclaration of %s; ANSI C requires static", /* 30 */
1.129 rillig 88: "'%s' has incomplete type '%s'", /* 31 */
1.1 cgd 89: "argument type defaults to 'int': %s", /* 32 */
90: "duplicate member name: %s", /* 33 */
1.118 rillig 91: "nonportable bit-field type '%s'", /* 34 */
1.86 rillig 92: "illegal bit-field type '%s'", /* 35 */
1.54 christos 93: "illegal bit-field size: %d", /* 36 */
1.1 cgd 94: "zero size bit-field", /* 37 */
95: "function illegal in structure or union", /* 38 */
1.30 christos 96: "zero sized array in struct is a C99 extension: %s", /* 39 */
1.158 ! rillig 97: "", /* never used */ /* 40 */
1.152 rillig 98: "bit-field in union is very unusual", /* 41 */
1.1 cgd 99: "forward reference to enum type", /* 42 */
100: "redefinition hides earlier one: %s", /* 43 */
101: "declaration introduces new type in ANSI C: %s %s", /* 44 */
102: "base type is really '%s %s'", /* 45 */
1.137 rillig 103: "%s tag '%s' redeclared as %s", /* 46 */
1.153 rillig 104: "zero sized %s is a C99 feature", /* 47 */
1.1 cgd 105: "overflow in enumeration values: %s", /* 48 */
1.153 rillig 106: "anonymous struct/union members is a C11 feature", /* 49 */
1.1 cgd 107: "a function is declared as an argument: %s", /* 50 */
108: "parameter mismatch: %d declared, %d defined", /* 51 */
109: "cannot initialize parameter: %s", /* 52 */
110: "declared argument %s is missing", /* 53 */
111: "trailing ',' prohibited in enum declaration", /* 54 */
112: "integral constant expression expected", /* 55 */
113: "integral constant too large", /* 56 */
114: "enumeration constant hides parameter: %s", /* 57 */
115: "type does not match prototype: %s", /* 58 */
116: "formal parameter lacks name: param #%d", /* 59 */
117: "void must be sole parameter", /* 60 */
118: "void parameter cannot have name: %s", /* 61 */
119: "function prototype parameters must have types", /* 62 */
120: "prototype does not match old-style definition", /* 63 */
121: "()-less function definition", /* 64 */
122: "%s has no named members", /* 65 */
1.130 rillig 123: "", /* 66 */
1.1 cgd 124: "cannot return incomplete type", /* 67 */
125: "typedef already qualified with '%s'", /* 68 */
126: "inappropriate qualifiers with 'void'", /* 69 */
127: "%soperand of '%s' is unsigned in ANSI C", /* 70 */
128: "too many characters in character constant", /* 71 */
129: "typedef declares no type name", /* 72 */
130: "empty character constant", /* 73 */
131: "no hex digits follow \\x", /* 74 */
132: "overflow in hex escape", /* 75 */
133: "character escape does not fit in character", /* 76 */
134: "bad octal digit %c", /* 77 */
1.141 rillig 135: "", /* unused */ /* 78 */
1.1 cgd 136: "dubious escape \\%c", /* 79 */
137: "dubious escape \\%o", /* 80 */
138: "\\a undefined in traditional C", /* 81 */
139: "\\x undefined in traditional C", /* 82 */
140: "storage class after type is obsolescent", /* 83 */
141: "ANSI C requires formal parameter before '...'", /* 84 */
142: "dubious tag declaration: %s %s", /* 85 */
143: "automatic hides external declaration: %s", /* 86 */
144: "static hides external declaration: %s", /* 87 */
145: "typedef hides external declaration: %s", /* 88 */
146: "typedef redeclared: %s", /* 89 */
147: "inconsistent redeclaration of extern: %s", /* 90 */
148: "declaration hides parameter: %s", /* 91 */
149: "inconsistent redeclaration of static: %s", /* 92 */
150: "dubious static function at block level: %s", /* 93 */
151: "function has illegal storage class: %s", /* 94 */
152: "declaration hides earlier one: %s", /* 95 */
153: "cannot dereference non-pointer type", /* 96 */
154: "suffix U is illegal in traditional C", /* 97 */
155: "suffixes F and L are illegal in traditional C", /* 98 */
1.95 rillig 156: "'%s' undefined", /* 99 */
1.1 cgd 157: "unary + is illegal in traditional C", /* 100 */
1.99 rillig 158: "type '%s' does not have member '%s'", /* 101 */
1.1 cgd 159: "illegal member use: %s", /* 102 */
1.125 rillig 160: "left operand of '.' must be struct or union, not '%s'", /* 103 */
161: "left operand of '->' must be pointer to struct or union, not '%s'", /* 104 */
1.1 cgd 162: "non-unique member requires struct/union %s", /* 105 */
163: "left operand of '->' must be pointer", /* 106 */
1.52 christos 164: "operands of '%s' have incompatible types (%s != %s)", /* 107 */
1.65 rillig 165: "operand of '%s' has invalid type (%s)", /* 108 */
1.1 cgd 166: "void type illegal in expression", /* 109 */
167: "pointer to function is not allowed here", /* 110 */
168: "unacceptable operand of '%s'", /* 111 */
169: "cannot take address of bit-field", /* 112 */
170: "cannot take address of register %s", /* 113 */
171: "%soperand of '%s' must be lvalue", /* 114 */
172: "%soperand of '%s' must be modifiable lvalue", /* 115 */
173: "illegal pointer subtraction", /* 116 */
1.75 rillig 174: "bitwise '%s' on signed value possibly nonportable", /* 117 */
1.1 cgd 175: "semantics of '%s' change in ANSI C; use explicit cast", /* 118 */
176: "conversion of '%s' to '%s' is out of range", /* 119 */
1.75 rillig 177: "bitwise '%s' on signed value nonportable", /* 120 */
1.1 cgd 178: "negative shift", /* 121 */
1.103 rillig 179: "shift amount %llu is greater than bit-size %llu of '%s'", /* 122 */
1.148 rillig 180: "illegal combination of %s '%s' and %s '%s', op '%s'", /* 123 */
1.136 rillig 181: "illegal combination of '%s' and '%s', op '%s'", /* 124 */
1.1 cgd 182: "ANSI C forbids ordered comparisons of pointers to functions",/* 125 */
1.69 rillig 183: "incompatible types '%s' and '%s' in conditional", /* 126 */
1.1 cgd 184: "'&' before array or function: ignored", /* 127 */
1.39 christos 185: "operands have incompatible pointer types, op %s (%s != %s)", /* 128 */
1.1 cgd 186: "expression has null effect", /* 129 */
1.84 rillig 187: "enum type mismatch: '%s' '%s' '%s'", /* 130 */
1.1 cgd 188: "conversion to '%s' may sign-extend incorrectly", /* 131 */
1.29 christos 189: "conversion from '%s' to '%s' may lose accuracy", /* 132 */
1.1 cgd 190: "conversion of pointer to '%s' loses bits", /* 133 */
191: "conversion of pointer to '%s' may lose bits", /* 134 */
1.82 rillig 192: "converting '%s' to '%s' may cause alignment problem", /* 135 */
1.1 cgd 193: "cannot do pointer arithmetic on operand of unknown size", /* 136 */
194: "use of incomplete enum type, op %s", /* 137 */
195: "unknown operand size, op %s", /* 138 */
196: "division by 0", /* 139 */
197: "modulus by 0", /* 140 */
1.139 rillig 198: "integer overflow detected, op '%s'", /* 141 */
1.1 cgd 199: "floating point overflow detected, op %s", /* 142 */
1.42 christos 200: "cannot take size/alignment of incomplete type", /* 143 */
1.155 rillig 201: "cannot take size/alignment of function type '%s'", /* 144 */
1.42 christos 202: "cannot take size/alignment of bit-field", /* 145 */
203: "cannot take size/alignment of void", /* 146 */
1.131 rillig 204: "invalid cast from '%s' to '%s'", /* 147 */
1.1 cgd 205: "improper cast of void expression", /* 148 */
1.47 christos 206: "illegal function (type %s)", /* 149 */
1.1 cgd 207: "argument mismatch: %d arg%s passed, %d expected", /* 150 */
208: "void expressions may not be arguments, arg #%d", /* 151 */
209: "argument cannot have unknown size, arg #%d", /* 152 */
1.83 rillig 210: "converting '%s' to incompatible '%s' for argument %d", /* 153 */
1.49 christos 211: "illegal combination of %s (%s) and %s (%s), arg #%d", /* 154 */
1.121 rillig 212: "passing '%s' to incompatible '%s', arg #%d", /* 155 */
1.67 rillig 213: "enum type mismatch, arg #%d (%s != %s)", /* 156 */
1.1 cgd 214: "ANSI C treats constant as unsigned", /* 157 */
1.58 rillig 215: "%s may be used before set", /* 158 */
1.1 cgd 216: "assignment in conditional context", /* 159 */
217: "operator '==' found where '=' was expected", /* 160 */
218: "constant in conditional context", /* 161 */
1.11 mycroft 219: "comparison of %s with %s, op %s", /* 162 */
1.1 cgd 220: "a cast does not yield an lvalue", /* 163 */
221: "assignment of negative constant to unsigned type", /* 164 */
222: "constant truncated by assignment", /* 165 */
223: "precision lost in bit-field assignment", /* 166 */
224: "array subscript cannot be negative: %ld", /* 167 */
225: "array subscript cannot be > %d: %ld", /* 168 */
226: "precedence confusion possible: parenthesize!", /* 169 */
227: "first operand must have scalar type, op ? :", /* 170 */
1.92 rillig 228: "cannot assign to '%s' from '%s'", /* 171 */
1.1 cgd 229: "too many struct/union initializers", /* 172 */
1.34 christos 230: "too many array initializers, expected %d", /* 173 */
1.1 cgd 231: "too many initializers", /* 174 */
1.98 rillig 232: "initialization of incomplete type '%s'", /* 175 */
1.97 rillig 233: "", /* no longer used */ /* 176 */
1.1 cgd 234: "non-constant initializer", /* 177 */
235: "initializer does not fit", /* 178 */
1.150 rillig 236: "cannot initialize struct/union with no named member", /* 179 */
1.1 cgd 237: "bit-field initializer does not fit", /* 180 */
238: "{}-enclosed initializer required", /* 181 */
1.39 christos 239: "incompatible pointer types (%s != %s)", /* 182 */
1.58 rillig 240: "illegal combination of %s (%s) and %s (%s)", /* 183 */
1.136 rillig 241: "illegal combination of '%s' and '%s'", /* 184 */
1.88 rillig 242: "cannot initialize '%s' from '%s'", /* 185 */
1.81 rillig 243: "bit-field initialization is illegal in traditional C", /* 186 */
1.149 rillig 244: "string literal too long (%lu) for target array (%lu)", /* 187 */
1.1 cgd 245: "no automatic aggregate initialization in traditional C", /* 188 */
1.70 rillig 246: "", /* no longer used */ /* 189 */
1.1 cgd 247: "empty array declaration: %s", /* 190 */
1.106 rillig 248: "'%s' set but not used in function '%s'", /* 191 */
249: "'%s' unused in function '%s'", /* 192 */
1.1 cgd 250: "statement not reached", /* 193 */
251: "label %s redefined", /* 194 */
252: "case not in switch", /* 195 */
253: "case label affected by conversion", /* 196 */
254: "non-constant case expression", /* 197 */
255: "non-integral case expression", /* 198 */
256: "duplicate case in switch: %ld", /* 199 */
257: "duplicate case in switch: %lu", /* 200 */
258: "default outside switch", /* 201 */
259: "duplicate default in switch", /* 202 */
1.138 rillig 260: "case label must be of type 'int' in traditional C", /* 203 */
1.1 cgd 261: "controlling expressions must have scalar type", /* 204 */
262: "switch expression must have integral type", /* 205 */
263: "enumeration value(s) not handled in switch", /* 206 */
264: "loop not entered at top", /* 207 */
265: "break outside loop or switch", /* 208 */
266: "continue outside loop", /* 209 */
1.81 rillig 267: "enum type mismatch between '%s' and '%s' in initialization", /* 210 */
1.53 christos 268: "return value type mismatch (%s) and (%s)", /* 211 */
1.1 cgd 269: "cannot return incomplete type", /* 212 */
270: "void function %s cannot return value", /* 213 */
1.133 rillig 271: "function '%s' expects to return value", /* 214 */
1.122 rillig 272: "function '%s' implicitly declared to return int", /* 215 */
1.1 cgd 273: "function %s has return (e); and return;", /* 216 */
274: "function %s falls off bottom without returning value", /* 217 */
275: "ANSI C treats constant as unsigned, op %s", /* 218 */
276: "concatenated strings are illegal in traditional C", /* 219 */
277: "fallthrough on case statement", /* 220 */
1.81 rillig 278: "initialization of unsigned with negative constant", /* 221 */
1.1 cgd 279: "conversion of negative constant to unsigned type", /* 222 */
280: "end-of-loop code not reached", /* 223 */
281: "cannot recover from previous errors", /* 224 */
282: "static function called but not defined: %s()", /* 225 */
283: "static variable %s unused", /* 226 */
284: "const object %s should have initializer", /* 227 */
285: "function cannot return const or volatile object", /* 228 */
1.83 rillig 286: "converting '%s' to '%s' is questionable", /* 229 */
1.146 rillig 287: "nonportable character comparison '%s %d'", /* 230 */
1.106 rillig 288: "argument '%s' unused in function '%s'", /* 231 */
1.128 rillig 289: "label '%s' unused in function '%s'", /* 232 */
1.1 cgd 290: "struct %s never defined", /* 233 */
291: "union %s never defined", /* 234 */
292: "enum %s never defined", /* 235 */
293: "static function %s unused", /* 236 */
294: "redeclaration of formal parameter %s", /* 237 */
1.81 rillig 295: "initialization of union is illegal in traditional C", /* 238 */
1.101 rillig 296: "constant argument to '!'", /* 239 */
1.36 christos 297: "assignment of different structures (%s != %s)", /* 240 */
1.1 cgd 298: "dubious operation on enum, op %s", /* 241 */
299: "combination of '%s' and '%s', op %s", /* 242 */
1.11 mycroft 300: "dubious comparison of enums, op %s", /* 243 */
1.1 cgd 301: "illegal structure pointer combination", /* 244 */
1.85 rillig 302: "incompatible structure pointers: '%s' '%s' '%s'", /* 245 */
1.1 cgd 303: "dubious conversion of enum to '%s'", /* 246 */
1.71 rillig 304: "pointer cast from '%s' to '%s' may be troublesome", /* 247 */
1.1 cgd 305: "floating-point constant out of range", /* 248 */
1.33 christos 306: "syntax error '%s'", /* 249 */
1.1 cgd 307: "unknown character \\%o", /* 250 */
308: "malformed integer constant", /* 251 */
309: "integer constant out of range", /* 252 */
310: "unterminated character constant", /* 253 */
311: "newline in string or char constant", /* 254 */
312: "undefined or invalid # directive", /* 255 */
313: "unterminated comment", /* 256 */
314: "extra characters in lint comment", /* 257 */
315: "unterminated string constant", /* 258 */
1.78 rillig 316: "argument #%d is converted from '%s' to '%s' due to prototype", /* 259 */
1.1 cgd 317: "previous declaration of %s", /* 260 */
318: "previous definition of %s", /* 261 */
319: "\\\" inside character constants undefined in traditional C", /* 262 */
320: "\\? undefined in traditional C", /* 263 */
321: "\\v undefined in traditional C", /* 264 */
1.151 rillig 322: "%s does not support 'long long'", /* 265 */
1.1 cgd 323: "'long double' is illegal in traditional C", /* 266 */
324: "shift equal to size of object", /* 267 */
1.4 jpo 325: "variable declared inline: %s", /* 268 */
326: "argument declared inline: %s", /* 269 */
1.1 cgd 327: "function prototypes are illegal in traditional C", /* 270 */
1.138 rillig 328: "switch expression must be of type 'int' in traditional C", /* 271 */
1.1 cgd 329: "empty translation unit", /* 272 */
330: "bit-field type '%s' invalid in ANSI C", /* 273 */
1.11 mycroft 331: "ANSI C forbids comparison of %s with %s", /* 274 */
1.72 rillig 332: "cast discards 'const' from type '%s'", /* 275 */
1.35 christos 333: "__%s__ is illegal for type %s", /* 276 */
1.81 rillig 334: "initialization of '%s' with '%s'", /* 277 */
1.1 cgd 335: "combination of '%s' and '%s', arg #%d", /* 278 */
336: "combination of '%s' and '%s' in return", /* 279 */
337: "must be outside function: /* %s */", /* 280 */
338: "duplicate use of /* %s */", /* 281 */
339: "must precede function definition: /* %s */", /* 282 */
340: "argument number mismatch with directive: /* %s */", /* 283 */
341: "fallthrough on default statement", /* 284 */
342: "prototype declaration", /* 285 */
343: "function definition is not a prototype", /* 286 */
344: "function declaration is not a prototype", /* 287 */
345: "dubious use of /* VARARGS */ with /* %s */", /* 288 */
346: "can't be used together: /* PRINTFLIKE */ /* SCANFLIKE */", /* 289 */
347: "static function %s declared but not defined", /* 290 */
348: "invalid multibyte character", /* 291 */
349: "cannot concatenate wide and regular string literals", /* 292 */
350: "argument %d must be 'char *' for PRINTFLIKE/SCANFLIKE", /* 293 */
351: "multi-character character constant", /* 294 */
352: "conversion of '%s' to '%s' is out of range, arg #%d", /* 295 */
353: "conversion of negative constant to unsigned type, arg #%d", /* 296 */
354: "conversion to '%s' may sign-extend incorrectly, arg #%d", /* 297 */
1.29 christos 355: "conversion from '%s' to '%s' may lose accuracy, arg #%d", /* 298 */
1.1 cgd 356: "prototype does not match old style definition, arg #%d", /* 299 */
357: "old style definition", /* 300 */
358: "array of incomplete type", /* 301 */
359: "%s returns pointer to automatic object", /* 302 */
360: "ANSI C forbids conversion of %s to %s", /* 303 */
361: "ANSI C forbids conversion of %s to %s, arg #%d", /* 304 */
362: "ANSI C forbids conversion of %s to %s, op %s", /* 305 */
363: "constant truncated by conversion, op %s", /* 306 */
364: "static variable %s set but not used", /* 307 */
1.62 rillig 365: "invalid type for _Complex", /* 308 */
1.117 rillig 366: "extra bits set to 0 in conversion of '%s' to '%s', op '%s'", /* 309 */
1.9 cgd 367: "symbol renaming can't be used on function arguments", /* 310 */
368: "symbol renaming can't be used on automatic variables", /* 311 */
1.151 rillig 369: "%s does not support // comments", /* 312 */
1.153 rillig 370: "struct or union member name in initializer is a C99 feature",/* 313 */
1.20 christos 371: "%s is not a structure or a union", /* 314 */
372: "GCC style struct or union member name in initializer", /* 315 */
1.45 christos 373: "__FUNCTION__/__PRETTY_FUNCTION__ is a GCC extension", /* 316 */
1.153 rillig 374: "__func__ is a C99 feature", /* 317 */
1.32 christos 375: "variable array dimension is a C99/GCC extension", /* 318 */
1.153 rillig 376: "compound literals are a C99/GCC extension", /* 319 */
1.24 christos 377: "({ }) is a GCC extension", /* 320 */
1.153 rillig 378: "array initializer with designators is a C99 feature", /* 321 */
1.30 christos 379: "zero sized array is a C99 extension", /* 322 */
1.37 dsl 380: "continue in 'do ... while (0)' loop", /* 323 */
1.38 christos 381: "suggest cast from '%s' to '%s' on op %s to avoid overflow", /* 324 */
1.58 rillig 382: "variable declaration in for loop", /* 325 */
1.43 christos 383: "%s attribute ignored for %s", /* 326 */
1.89 rillig 384: "declarations after statements is a C99 feature", /* 327 */
1.134 rillig 385: "union cast is a GCC extension", /* 328 */
1.51 christos 386: "type '%s' is not a member of '%s'", /* 329 */
1.66 rillig 387: "operand of '%s' must be bool, not '%s'", /* 330 */
388: "left operand of '%s' must be bool, not '%s'", /* 331 */
389: "right operand of '%s' must be bool, not '%s'", /* 332 */
390: "controlling expression must be bool, not '%s'", /* 333 */
391: "argument #%d expects '%s', gets passed '%s'", /* 334 */
392: "operand of '%s' must not be bool", /* 335 */
393: "left operand of '%s' must not be bool", /* 336 */
394: "right operand of '%s' must not be bool", /* 337 */
1.79 rillig 395: "option '%c' should be handled in the switch", /* 338 */
396: "option '%c' should be listed in the options string", /* 339 */
1.126 rillig 397: "initialization with '[a...b]' is a GCC extension", /* 340 */
1.102 rillig 398: "argument to '%s' must be 'unsigned char' or EOF, not '%s'", /* 341 */
399: "argument to '%s' must be cast to 'unsigned char', not to '%s'", /* 342 */
1.108 rillig 400: "static array size is a C11 extension", /* 343 */
1.119 rillig 401: "bit-field of type plain 'int' has implementation-defined signedness", /* 344 */
1.120 rillig 402: "generic selection requires C11 or later", /* 345 */
1.135 rillig 403: "call to '%s' effectively discards 'const' from argument", /* 346 */
1.145 rillig 404: "redeclaration of '%s' with type '%s', expected '%s'", /* 347 */
1.147 rillig 405: "maximum value %d of '%s' does not match maximum array index %d", /* 348 */
1.1 cgd 406: };
407:
1.104 rillig 408: static struct include_level {
409: const char *filename;
410: int lineno;
411: struct include_level *by;
412: } *includes;
413:
414:
415: void
1.105 rillig 416: update_location(const char *filename, int lineno, bool is_begin, bool is_end)
1.104 rillig 417: {
418: struct include_level *top;
419:
420: top = includes;
421: if (is_begin && top != NULL)
422: top->lineno = curr_pos.p_line;
423:
424: if (top == NULL || is_begin) {
425: top = xmalloc(sizeof(*top));
426: top->filename = filename;
427: top->lineno = lineno;
428: top->by = includes;
429: includes = top;
430: } else {
1.109 rillig 431: if (is_end) {
1.104 rillig 432: includes = top->by;
433: free(top);
434: top = includes;
435: }
1.123 rillig 436: if (top != NULL) {
437: top->filename = filename;
438: top->lineno = lineno;
439: }
1.104 rillig 440: }
441: }
442:
443: static void
444: print_stack_trace(void)
445: {
1.105 rillig 446: const struct include_level *top;
1.104 rillig 447:
448: if ((top = includes) == NULL)
449: return;
1.105 rillig 450: /*
451: * Skip the innermost include level since it is already listed in the
452: * diagnostic itself. Furthermore, its lineno is the line number of
453: * the last '#' line, not the current line.
454: */
1.104 rillig 455: for (top = top->by; top != NULL; top = top->by)
456: printf("\tincluded from %s(%d)\n", top->filename, top->lineno);
457: }
458:
1.1 cgd 459: /*
1.12 christos 460: * print a list of the messages with their ids
461: */
462: void
1.15 lukem 463: msglist(void)
1.12 christos 464: {
1.40 christos 465: size_t i;
1.12 christos 466:
1.143 rillig 467: for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++) {
468: if (msgs[i][0] != '\0')
469: printf("%zu\t%s\n", i, msgs[i]);
470: else
471: printf("---\t(no longer used)\n");
472: }
1.12 christos 473: }
474:
475: /*
1.56 rillig 476: * If Fflag is not set, lbasename() returns a pointer to the last
1.1 cgd 477: * component of the path, otherwise it returns the argument.
478: */
479: static const char *
1.18 tv 480: lbasename(const char *path)
1.1 cgd 481: {
1.68 rillig 482: const char *p, *base, *dir;
1.1 cgd 483:
484: if (Fflag)
1.57 rillig 485: return path;
1.1 cgd 486:
1.68 rillig 487: p = base = dir = path;
488: while (*p != '\0') {
489: if (*p++ == '/') {
490: dir = base;
491: base = p;
1.1 cgd 492: }
493: }
1.68 rillig 494: return *base != '\0' ? base : dir;
1.1 cgd 495: }
496:
1.3 jpo 497: static void
1.116 rillig 498: verror_at(int msgid, const pos_t *pos, va_list ap)
1.3 jpo 499: {
500: const char *fn;
501:
1.115 rillig 502: if (ERR_ISSET(msgid, &msgset))
1.12 christos 503: return;
504:
1.116 rillig 505: fn = lbasename(pos->p_file);
506: (void)printf("%s(%d): error: ", fn, pos->p_line);
1.115 rillig 507: (void)vprintf(msgs[msgid], ap);
508: (void)printf(" [%d]\n", msgid);
1.3 jpo 509: nerr++;
1.104 rillig 510: print_stack_trace();
1.3 jpo 511: }
512:
513: static void
1.116 rillig 514: vwarning_at(int msgid, const pos_t *pos, va_list ap)
1.3 jpo 515: {
516: const char *fn;
517:
1.115 rillig 518: if (ERR_ISSET(msgid, &msgset))
1.12 christos 519: return;
520:
1.132 rillig 521: debug_step("%s: lwarn=%d msgid=%d", __func__, lwarn, msgid);
1.115 rillig 522: if (lwarn == LWARN_NONE || lwarn == msgid)
1.3 jpo 523: /* this warning is suppressed by a LINTED comment */
524: return;
525:
1.116 rillig 526: fn = lbasename(pos->p_file);
527: (void)printf("%s(%d): warning: ", fn, pos->p_line);
1.115 rillig 528: (void)vprintf(msgs[msgid], ap);
529: (void)printf(" [%d]\n", msgid);
1.12 christos 530: if (wflag)
531: nerr++;
1.104 rillig 532: print_stack_trace();
1.3 jpo 533: }
534:
1.113 rillig 535: static void
1.116 rillig 536: vmessage_at(int msgid, const pos_t *pos, va_list ap)
1.113 rillig 537: {
538: const char *fn;
539:
1.115 rillig 540: if (ERR_ISSET(msgid, &msgset))
1.113 rillig 541: return;
542:
1.116 rillig 543: fn = lbasename(pos->p_file);
544: (void)printf("%s(%d): ", fn, pos->p_line);
1.115 rillig 545: (void)vprintf(msgs[msgid], ap);
546: (void)printf(" [%d]\n", msgid);
1.113 rillig 547: print_stack_trace();
548: }
549:
550: void
1.116 rillig 551: (error_at)(int msgid, const pos_t *pos, ...)
1.113 rillig 552: {
553: va_list ap;
554:
555: va_start(ap, pos);
1.115 rillig 556: verror_at(msgid, pos, ap);
1.113 rillig 557: va_end(ap);
558: }
559:
1.3 jpo 560: void
1.115 rillig 561: (error)(int msgid, ...)
1.1 cgd 562: {
563: va_list ap;
564:
1.115 rillig 565: va_start(ap, msgid);
1.116 rillig 566: verror_at(msgid, &curr_pos, ap);
1.1 cgd 567: va_end(ap);
568: }
569:
1.3 jpo 570: void
1.96 rillig 571: internal_error(const char *file, int line, const char *msg, ...)
1.1 cgd 572: {
573: va_list ap;
574: const char *fn;
575:
1.94 rillig 576: fn = lbasename(curr_pos.p_file);
1.144 rillig 577: (void)fflush(stdout);
1.94 rillig 578: (void)fprintf(stderr, "lint: internal error in %s:%d near %s:%d: ",
579: file, line, fn, curr_pos.p_line);
1.1 cgd 580: va_start(ap, msg);
581: (void)vfprintf(stderr, msg, ap);
1.94 rillig 582: va_end(ap);
1.1 cgd 583: (void)fprintf(stderr, "\n");
1.104 rillig 584: print_stack_trace();
1.45 christos 585: abort();
1.1 cgd 586: }
587:
1.3 jpo 588: void
1.59 rillig 589: assert_failed(const char *file, int line, const char *func, const char *cond)
590: {
591: const char *fn;
592:
593: fn = lbasename(curr_pos.p_file);
1.144 rillig 594: (void)fflush(stdout);
1.59 rillig 595: (void)fprintf(stderr,
596: "lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
597: cond, func, file, line, fn, curr_pos.p_line);
1.104 rillig 598: print_stack_trace();
1.156 rillig 599: (void)fflush(stdout);
1.59 rillig 600: abort();
601: }
602:
603: void
1.116 rillig 604: (warning_at)(int msgid, const pos_t *pos, ...)
1.113 rillig 605: {
606: va_list ap;
607:
608: va_start(ap, pos);
1.115 rillig 609: vwarning_at(msgid, pos, ap);
1.113 rillig 610: va_end(ap);
611: }
612:
613: void
1.115 rillig 614: (warning)(int msgid, ...)
1.1 cgd 615: {
1.3 jpo 616: va_list ap;
617:
1.115 rillig 618: va_start(ap, msgid);
1.116 rillig 619: vwarning_at(msgid, &curr_pos, ap);
1.113 rillig 620: va_end(ap);
621: }
622:
623: void
1.116 rillig 624: (message_at)(int msgid, const pos_t *pos, ...)
1.113 rillig 625: {
626: va_list ap;
627:
628: va_start(ap, pos);
1.115 rillig 629: vmessage_at(msgid, pos, ap);
1.3 jpo 630: va_end(ap);
631: }
632:
1.26 perry 633: /*
634: * XXX I think the logic is possibly somewhat screwed up here. The
635: * question is, how do we want to interpret the -s and -S flags going
636: * forward? We need to answer that and then we can fix this to be
637: * "right"... [perry, 2 Nov 2002]
638: */
1.63 rillig 639: void
1.115 rillig 640: (c99ism)(int msgid, ...)
1.25 perry 641: {
642: va_list ap;
1.63 rillig 643: bool extensions_ok = Sflag || gflag;
1.25 perry 644:
1.115 rillig 645: va_start(ap, msgid);
1.63 rillig 646: if (sflag && !extensions_ok) {
1.116 rillig 647: verror_at(msgid, &curr_pos, ap);
1.63 rillig 648: } else if (sflag || !extensions_ok) {
1.116 rillig 649: vwarning_at(msgid, &curr_pos, ap);
1.25 perry 650: }
651: va_end(ap);
1.1 cgd 652: }
653:
1.108 rillig 654: void
1.115 rillig 655: (c11ism)(int msgid, ...)
1.108 rillig 656: {
657: va_list ap;
658:
1.111 christos 659: if (c11flag || gflag)
1.110 rillig 660: return;
1.115 rillig 661: va_start(ap, msgid);
1.116 rillig 662: verror_at(msgid, &curr_pos, ap);
1.108 rillig 663: va_end(ap);
664: }
665:
1.63 rillig 666: void
1.115 rillig 667: (gnuism)(int msgid, ...)
1.1 cgd 668: {
669: va_list ap;
670:
1.115 rillig 671: va_start(ap, msgid);
1.3 jpo 672: if (sflag && !gflag) {
1.116 rillig 673: verror_at(msgid, &curr_pos, ap);
1.63 rillig 674: } else if (sflag || !gflag) {
1.116 rillig 675: vwarning_at(msgid, &curr_pos, ap);
1.3 jpo 676: }
1.1 cgd 677: va_end(ap);
678: }
CVSweb <webmaster@jp.NetBSD.org>