blob: 90759d98915c5158c0c7987962952326065b8b56 [file] [log] [blame]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -08001# python3
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08002# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns for C/C++ compiler, but not clang-tidy."""
17
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070018# No need of doc strings for trivial small functions.
19# pylint:disable=missing-function-docstring
20
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080021import re
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080022
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080023# pylint:disable=relative-beyond-top-level
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080024from .severity import Severity
25
26
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -080027def cpp_warn(severity, description, pattern_list):
28 return {
29 'category': 'C/C++',
30 'severity': severity,
31 'description': description,
32 'patterns': pattern_list
33 }
34
35
36def fixmenow(description, pattern_list):
37 return cpp_warn(Severity.FIXMENOW, description, pattern_list)
38
39
40def high(description, pattern_list):
41 return cpp_warn(Severity.HIGH, description, pattern_list)
42
43
44def medium(description, pattern_list):
45 return cpp_warn(Severity.MEDIUM, description, pattern_list)
46
47
48def low(description, pattern_list):
49 return cpp_warn(Severity.LOW, description, pattern_list)
50
51
52def skip(description, pattern_list):
53 return cpp_warn(Severity.SKIP, description, pattern_list)
54
55
56def harmless(description, pattern_list):
57 return cpp_warn(Severity.HARMLESS, description, pattern_list)
58
59
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -080060warn_patterns = [
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070061 # pylint does not recognize g-inconsistent-quotes
62 # pylint:disable=line-too-long,bad-option-value,g-inconsistent-quotes
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -080063 medium('Implicit function declaration',
64 [r".*: warning: implicit declaration of function .+",
65 r".*: warning: implicitly declaring library function"]),
66 skip('skip, conflicting types for ...',
67 [r".*: warning: conflicting types for '.+'"]),
68 high('Expression always evaluates to true or false',
69 [r".*: warning: comparison is always .+ due to limited range of data type",
70 r".*: warning: comparison of unsigned .*expression .+ is always true",
71 r".*: warning: comparison of unsigned .*expression .+ is always false"]),
72 high('Use transient memory for control value',
73 [r".*: warning: .+Using such transient memory for the control value is .*dangerous."]),
74 high('Return address of stack memory',
75 [r".*: warning: Address of stack memory .+ returned to caller",
76 r".*: warning: Address of stack memory .+ will be a dangling reference"]),
77 high('Infinite recursion',
78 [r".*: warning: all paths through this function will call itself"]),
79 high('Potential buffer overflow',
80 [r".*: warning: Size argument is greater than .+ the destination buffer",
81 r".*: warning: Potential buffer overflow.",
82 r".*: warning: String copy function overflows destination buffer"]),
83 medium('Incompatible pointer types',
84 [r".*: warning: assignment from incompatible pointer type",
85 r".*: warning: return from incompatible pointer type",
86 r".*: warning: passing argument [0-9]+ of '.*' from incompatible pointer type",
87 r".*: warning: initialization from incompatible pointer type"]),
88 high('Incompatible declaration of built in function',
89 [r".*: warning: incompatible implicit declaration of built-in function .+"]),
90 high('Incompatible redeclaration of library function',
91 [r".*: warning: incompatible redeclaration of library function .+"]),
92 high('Null passed as non-null argument',
93 [r".*: warning: Null passed to a callee that requires a non-null"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -070094 medium('Unused command line argument',
95 [r".*: warning: argument unused during compilation: .+"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -080096 medium('Unused parameter',
97 [r".*: warning: unused parameter '.*'"]),
98 medium('Unused function, variable, label, comparison, etc.',
99 [r".*: warning: '.+' defined but not used",
100 r".*: warning: unused function '.+'",
101 r".*: warning: unused label '.+'",
102 r".*: warning: relational comparison result unused",
103 r".*: warning: lambda capture .* is not used",
104 r".*: warning: private field '.+' is not used",
105 r".*: warning: unused variable '.+'"]),
106 medium('Statement with no effect or result unused',
107 [r".*: warning: statement with no effect",
108 r".*: warning: expression result unused"]),
109 medium('Ignoreing return value of function',
110 [r".*: warning: ignoring return value of function .+Wunused-result"]),
111 medium('Missing initializer',
112 [r".*: warning: missing initializer"]),
113 medium('Need virtual destructor',
114 [r".*: warning: delete called .* has virtual functions but non-virtual destructor"]),
115 skip('skip, near initialization for ...',
116 [r".*: warning: \(near initialization for '.+'\)"]),
117 medium('Expansion of data or time macro',
118 [r".*: warning: expansion of date or time macro is not reproducible"]),
119 medium('Macro expansion has undefined behavior',
120 [r".*: warning: macro expansion .* has undefined behavior"]),
121 medium('Format string does not match arguments',
122 [r".*: warning: format '.+' expects type '.+', but argument [0-9]+ has type '.+'",
123 r".*: warning: more '%' conversions than data arguments",
124 r".*: warning: data argument not used by format string",
125 r".*: warning: incomplete format specifier",
126 r".*: warning: unknown conversion type .* in format",
127 r".*: warning: format .+ expects .+ but argument .+Wformat=",
128 r".*: warning: field precision should have .+ but argument has .+Wformat",
129 r".*: warning: format specifies type .+ but the argument has .*type .+Wformat"]),
130 medium('Too many arguments for format string',
131 [r".*: warning: too many arguments for format"]),
132 medium('Too many arguments in call',
133 [r".*: warning: too many arguments in call to "]),
134 medium('Invalid format specifier',
135 [r".*: warning: invalid .+ specifier '.+'.+format-invalid-specifier"]),
136 medium('Comparison between signed and unsigned',
137 [r".*: warning: comparison between signed and unsigned",
138 r".*: warning: comparison of promoted \~unsigned with unsigned",
139 r".*: warning: signed and unsigned type in conditional expression"]),
140 medium('Comparison between enum and non-enum',
141 [r".*: warning: enumeral and non-enumeral type in conditional expression"]),
142 medium('libpng: zero area',
143 [r".*libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area"]),
144 medium('Missing braces around initializer',
145 [r".*: warning: missing braces around initializer.*"]),
146 harmless('No newline at end of file',
147 [r".*: warning: no newline at end of file"]),
148 harmless('Missing space after macro name',
149 [r".*: warning: missing whitespace after the macro name"]),
150 low('Cast increases required alignment',
151 [r".*: warning: cast from .* to .* increases required alignment .*"]),
152 medium('Qualifier discarded',
153 [r".*: warning: passing argument [0-9]+ of '.+' discards qualifiers from pointer target type",
154 r".*: warning: assignment discards qualifiers from pointer target type",
155 r".*: warning: passing .+ to parameter of type .+ discards qualifiers",
156 r".*: warning: assigning to .+ from .+ discards qualifiers",
157 r".*: warning: initializing .+ discards qualifiers .+types-discards-qualifiers",
158 r".*: warning: return discards qualifiers from pointer target type"]),
159 medium('Unknown attribute',
160 [r".*: warning: unknown attribute '.+'"]),
161 medium('Attribute ignored',
162 [r".*: warning: '_*packed_*' attribute ignored",
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700163 r".*: warning: .* not supported .*Wignored-attributes",
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800164 r".*: warning: attribute declaration must precede definition .+ignored-attributes"]),
165 medium('Visibility problem',
166 [r".*: warning: declaration of '.+' will not be visible outside of this function"]),
167 medium('Visibility mismatch',
168 [r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"]),
169 medium('Shift count greater than width of type',
170 [r".*: warning: (left|right) shift count >= width of type"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700171 medium('Shift operator precedence',
172 [r".*: warning: operator .* has lower precedence .+Wshift-op-parentheses.+"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800173 medium('extern <foo> is initialized',
174 [r".*: warning: '.+' initialized and declared 'extern'",
175 r".*: warning: 'extern' variable has an initializer"]),
176 medium('Old style declaration',
177 [r".*: warning: 'static' is not at beginning of declaration"]),
178 medium('Missing return value',
179 [r".*: warning: control reaches end of non-void function"]),
180 medium('Implicit int type',
181 [r".*: warning: type specifier missing, defaults to 'int'",
182 r".*: warning: type defaults to 'int' in declaration of '.+'"]),
183 medium('Main function should return int',
184 [r".*: warning: return type of 'main' is not 'int'"]),
185 medium('Variable may be used uninitialized',
186 [r".*: warning: '.+' may be used uninitialized in this function"]),
187 high('Variable is used uninitialized',
188 [r".*: warning: '.+' is used uninitialized in this function",
189 r".*: warning: variable '.+' is uninitialized when used here"]),
190 medium('ld: possible enum size mismatch',
191 [r".*: warning: .* uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail"]),
192 medium('Pointer targets differ in signedness',
193 [r".*: warning: pointer targets in initialization differ in signedness",
194 r".*: warning: pointer targets in assignment differ in signedness",
195 r".*: warning: pointer targets in return differ in signedness",
196 r".*: warning: pointer targets in passing argument [0-9]+ of '.+' differ in signedness"]),
197 medium('Assuming overflow does not occur',
198 [r".*: warning: assuming signed overflow does not occur when assuming that .* is always (true|false)"]),
199 medium('Suggest adding braces around empty body',
200 [r".*: warning: suggest braces around empty body in an 'if' statement",
201 r".*: warning: empty body in an if-statement",
202 r".*: warning: suggest braces around empty body in an 'else' statement",
203 r".*: warning: empty body in an else-statement"]),
204 medium('Suggest adding parentheses',
205 [r".*: warning: suggest explicit braces to avoid ambiguous 'else'",
206 r".*: warning: suggest parentheses around arithmetic in operand of '.+'",
207 r".*: warning: suggest parentheses around comparison in operand of '.+'",
208 r".*: warning: logical not is only applied to the left hand side of this comparison",
209 r".*: warning: using the result of an assignment as a condition without parentheses",
210 r".*: warning: .+ has lower precedence than .+ be evaluated first .+Wparentheses",
211 r".*: warning: suggest parentheses around '.+?' .+ '.+?'",
212 r".*: warning: suggest parentheses around assignment used as truth value"]),
213 medium('Static variable used in non-static inline function',
214 [r".*: warning: '.+' is static but used in inline function '.+' which is not static"]),
215 medium('No type or storage class (will default to int)',
216 [r".*: warning: data definition has no type or storage class"]),
217 skip('skip, parameter name (without types) in function declaration',
218 [r".*: warning: parameter names \(without types\) in function declaration"]),
219 medium('Dereferencing <foo> breaks strict aliasing rules',
220 [r".*: warning: dereferencing .* break strict-aliasing rules"]),
221 medium('Cast from pointer to integer of different size',
222 [r".*: warning: cast from pointer to integer of different size",
223 r".*: warning: initialization makes pointer from integer without a cast"]),
224 medium('Cast to pointer from integer of different size',
225 [r".*: warning: cast to pointer from integer of different size"]),
226 medium('Macro redefined',
227 [r".*: warning: '.+' macro redefined"]),
228 skip('skip, ... location of the previous definition',
229 [r".*: warning: this is the location of the previous definition"]),
230 medium('ld: type and size of dynamic symbol are not defined',
231 [r".*: warning: type and size of dynamic symbol `.+' are not defined"]),
232 medium('Pointer from integer without cast',
233 [r".*: warning: assignment makes pointer from integer without a cast"]),
234 medium('Pointer from integer without cast',
235 [r".*: warning: passing argument [0-9]+ of '.+' makes pointer from integer without a cast"]),
236 medium('Integer from pointer without cast',
237 [r".*: warning: assignment makes integer from pointer without a cast"]),
238 medium('Integer from pointer without cast',
239 [r".*: warning: passing argument [0-9]+ of '.+' makes integer from pointer without a cast"]),
240 medium('Integer from pointer without cast',
241 [r".*: warning: return makes integer from pointer without a cast"]),
242 medium('Ignoring pragma',
243 [r".*: warning: ignoring #pragma .+"]),
244 medium('Pragma warning messages',
245 [r".*: warning: .+W#pragma-messages"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700246 medium('Pragma once in main file',
247 [r".*: warning: #pragma once in main file .+Wpragma-once-outside-header.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800248 medium('Variable might be clobbered by longjmp or vfork',
249 [r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"]),
250 medium('Argument might be clobbered by longjmp or vfork',
251 [r".*: warning: argument '.+' might be clobbered by 'longjmp' or 'vfork'"]),
252 medium('Redundant declaration',
253 [r".*: warning: redundant redeclaration of '.+'"]),
254 skip('skip, previous declaration ... was here',
255 [r".*: warning: previous declaration of '.+' was here"]),
256 high('Enum value not handled in switch',
257 [r".*: warning: .*enumeration value.* not handled in switch.+Wswitch"]),
258 medium('User defined warnings',
259 [r".*: warning: .* \[-Wuser-defined-warnings\]$"]),
260 medium('Taking address of temporary',
261 [r".*: warning: taking address of temporary"]),
262 medium('Taking address of packed member',
263 [r".*: warning: taking address of packed member"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700264 medium('Pack alignment value is modified',
265 [r".*: warning: .*#pragma pack alignment value is modified.*Wpragma-pack.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800266 medium('Possible broken line continuation',
267 [r".*: warning: backslash and newline separated by space"]),
268 medium('Undefined variable template',
269 [r".*: warning: instantiation of variable .* no definition is available"]),
270 medium('Inline function is not defined',
271 [r".*: warning: inline function '.*' is not defined"]),
272 medium('Excess elements in initializer',
273 [r".*: warning: excess elements in .+ initializer"]),
274 medium('Decimal constant is unsigned only in ISO C90',
275 [r".*: warning: this decimal constant is unsigned only in ISO C90"]),
276 medium('main is usually a function',
277 [r".*: warning: 'main' is usually a function"]),
278 medium('Typedef ignored',
279 [r".*: warning: 'typedef' was ignored in this declaration"]),
280 high('Address always evaluates to true',
281 [r".*: warning: the address of '.+' will always evaluate as 'true'"]),
282 fixmenow('Freeing a non-heap object',
283 [r".*: warning: attempt to free a non-heap object '.+'"]),
284 medium('Array subscript has type char',
285 [r".*: warning: array subscript .+ type 'char'.+Wchar-subscripts"]),
286 medium('Constant too large for type',
287 [r".*: warning: integer constant is too large for '.+' type"]),
288 medium('Constant too large for type, truncated',
289 [r".*: warning: large integer implicitly truncated to unsigned type"]),
290 medium('Overflow in expression',
291 [r".*: warning: overflow in expression; .*Winteger-overflow"]),
292 medium('Overflow in implicit constant conversion',
293 [r".*: warning: overflow in implicit constant conversion"]),
294 medium('Declaration does not declare anything',
295 [r".*: warning: declaration 'class .+' does not declare anything"]),
296 medium('Initialization order will be different',
297 [r".*: warning: '.+' will be initialized after",
298 r".*: warning: field .+ will be initialized after .+Wreorder"]),
299 skip('skip, ....',
300 [r".*: warning: '.+'"]),
301 skip('skip, base ...',
302 [r".*: warning: base '.+'"]),
303 skip('skip, when initialized here',
304 [r".*: warning: when initialized here"]),
305 medium('Parameter type not specified',
306 [r".*: warning: type of '.+' defaults to 'int'"]),
307 medium('Missing declarations',
308 [r".*: warning: declaration does not declare anything"]),
309 medium('Missing noreturn',
310 [r".*: warning: function '.*' could be declared with attribute 'noreturn'"]),
311 medium('User warning',
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -0700312 [r".*: warning: #warning \".+\""]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800313 medium('Vexing parsing problem',
314 [r".*: warning: empty parentheses interpreted as a function declaration"]),
315 medium('Dereferencing void*',
316 [r".*: warning: dereferencing 'void \*' pointer"]),
317 medium('Comparison of pointer and integer',
318 [r".*: warning: ordered comparison of pointer with integer zero",
319 r".*: warning: .*comparison between pointer and integer"]),
320 medium('Use of error-prone unary operator',
321 [r".*: warning: use of unary operator that may be intended as compound assignment"]),
322 medium('Conversion of string constant to non-const char*',
323 [r".*: warning: deprecated conversion from string constant to '.+'"]),
324 medium('Function declaration isn''t a prototype',
325 [r".*: warning: function declaration isn't a prototype"]),
326 medium('Type qualifiers ignored on function return value',
327 [r".*: warning: type qualifiers ignored on function return type",
328 r".*: warning: .+ type qualifier .+ has no effect .+Wignored-qualifiers"]),
329 medium('<foo> declared inside parameter list, scope limited to this definition',
330 [r".*: warning: '.+' declared inside parameter list"]),
331 skip('skip, its scope is only this ...',
332 [r".*: warning: its scope is only this definition or declaration, which is probably not what you want"]),
333 low('Line continuation inside comment',
334 [r".*: warning: multi-line comment"]),
335 low('Comment inside comment',
336 [r".*: warning: '.+' within block comment .*-Wcomment"]),
337 low('Deprecated declarations',
338 [r".*: warning: .+ is deprecated.+deprecated-declarations"]),
339 low('Deprecated register',
340 [r".*: warning: 'register' storage class specifier is deprecated"]),
341 low('Converts between pointers to integer types with different sign',
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700342 [r".*: warning: .+ converts between pointers to integer types .+Wpointer-sign\]"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800343 harmless('Extra tokens after #endif',
344 [r".*: warning: extra tokens at end of #endif directive"]),
345 medium('Comparison between different enums',
346 [r".*: warning: comparison between '.+' and '.+'.+Wenum-compare",
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700347 r".*: warning: comparison of .* enumeration types .*-Wenum-compare.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800348 medium('Conversion may change value',
349 [r".*: warning: converting negative value '.+' to '.+'",
350 r".*: warning: conversion to '.+' .+ may (alter|change)"]),
351 medium('Converting to non-pointer type from NULL',
352 [r".*: warning: converting to non-pointer type '.+' from NULL"]),
353 medium('Implicit sign conversion',
354 [r".*: warning: implicit conversion changes signedness"]),
355 medium('Converting NULL to non-pointer type',
356 [r".*: warning: implicit conversion of NULL constant to '.+'"]),
357 medium('Zero used as null pointer',
358 [r".*: warning: expression .* zero treated as a null pointer constant"]),
359 medium('Compare pointer to null character',
360 [r".*: warning: comparing a pointer to a null character constant"]),
361 medium('Implicit conversion changes value or loses precision',
362 [r".*: warning: implicit conversion .* changes value from .* to .*-conversion",
363 r".*: warning: implicit conversion loses integer precision:"]),
364 medium('Passing NULL as non-pointer argument',
365 [r".*: warning: passing NULL to non-pointer argument [0-9]+ of '.+'"]),
366 medium('Class seems unusable because of private ctor/dtor',
367 [r".*: warning: all member functions in class '.+' are private"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800368 # skip this next one, because it only points out some RefBase-based classes
369 # where having a private destructor is perfectly fine
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800370 skip('Class seems unusable because of private ctor/dtor',
371 [r".*: warning: 'class .+' only defines a private destructor and has no friends"]),
372 medium('Class seems unusable because of private ctor/dtor',
373 [r".*: warning: 'class .+' only defines private constructors and has no friends"]),
374 medium('In-class initializer for static const float/double',
375 [r".*: warning: in-class initializer for static data member of .+const (float|double)"]),
376 medium('void* used in arithmetic',
377 [r".*: warning: pointer of type 'void \*' used in (arithmetic|subtraction)",
378 r".*: warning: arithmetic on .+ to void is a GNU extension.*Wpointer-arith",
379 r".*: warning: wrong type argument to increment"]),
380 medium('Overload resolution chose to promote from unsigned or enum to signed type',
381 [r".*: warning: passing '.+' chooses '.+' over '.+'.*Wsign-promo"]),
382 skip('skip, in call to ...',
383 [r".*: warning: in call to '.+'"]),
384 high('Base should be explicitly initialized in copy constructor',
385 [r".*: warning: base class '.+' should be explicitly initialized in the copy constructor"]),
386 medium('Return value from void function',
387 [r".*: warning: 'return' with a value, in function returning void"]),
388 medium('Multi-character character constant',
389 [r".*: warning: multi-character character constant"]),
390 medium('Conversion from string literal to char*',
391 [r".*: warning: .+ does not allow conversion from string literal to 'char \*'"]),
392 low('Extra \';\'',
393 [r".*: warning: extra ';' .+extra-semi"]),
394 low('Useless specifier',
395 [r".*: warning: useless storage class specifier in empty declaration"]),
396 low('Duplicate declaration specifier',
397 [r".*: warning: duplicate '.+' declaration specifier"]),
398 low('Comparison of self is always false',
399 [r".*: self-comparison always evaluates to false"]),
400 low('Logical op with constant operand',
401 [r".*: use of logical '.+' with constant operand"]),
402 low('Needs a space between literal and string macro',
403 [r".*: warning: invalid suffix on literal.+ requires a space .+Wliteral-suffix"]),
404 low('Warnings from #warning',
405 [r".*: warning: .+-W#warnings"]),
406 low('Using float/int absolute value function with int/float argument',
407 [r".*: warning: using .+ absolute value function .+ when argument is .+ type .+Wabsolute-value",
408 r".*: warning: absolute value function '.+' given .+ which may cause truncation .+Wabsolute-value"]),
409 low('Using C++11 extensions',
410 [r".*: warning: 'auto' type specifier is a C\+\+11 extension"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700411 low('Using C++17 extensions',
412 [r".*: warning: .* a C\+\+17 extension .+Wc\+\+17-extensions"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800413 low('Refers to implicitly defined namespace',
414 [r".*: warning: using directive refers to implicitly-defined namespace .+"]),
415 low('Invalid pp token',
416 [r".*: warning: missing .+Winvalid-pp-token"]),
417 low('need glibc to link',
418 [r".*: warning: .* requires at runtime .* glibc .* for linking"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700419 low('Add braces to avoid dangling else',
420 [r".*: warning: add explicit braces to avoid dangling else"]),
421 low('Assigning value to self',
422 [r".*: warning: explicitly assigning value of .+ to itself"]),
423 low('Comparison of integers of different signs',
424 [r".*: warning: comparison of integers of different signs.+sign-compare"]),
425 low('Incompatible pointer types',
426 [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]),
427 low('Missing braces',
428 [r".*: warning: suggest braces around initialization of",
429 r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
430 r".*: warning: braces around scalar initializer"]),
431 low('Missing field initializers',
432 [r".*: warning: missing field '.+' initializer"]),
433 low('Typedef redefinition',
434 [r".*: warning: redefinition of typedef '.+' is a C11 feature"]),
435 low('GNU old-style field designator',
436 [r".*: warning: use of GNU old-style field designator extension"]),
437 low('Initializer overrides prior initialization',
438 [r".*: warning: initializer overrides prior initialization of this subobject"]),
439 low('GNU extension, variable sized type not at end',
440 [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]),
441 low('Comparison of constant is always false/true',
442 [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]),
443 low('Hides overloaded virtual function',
444 [r".*: '.+' hides overloaded virtual function"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800445 medium('Operator new returns NULL',
446 [r".*: warning: 'operator new' must not return NULL unless it is declared 'throw\(\)' .+"]),
447 medium('NULL used in arithmetic',
448 [r".*: warning: NULL used in arithmetic",
449 r".*: warning: comparison between NULL and non-pointer"]),
450 medium('Misspelled header guard',
451 [r".*: warning: '.+' is used as a header guard .+ followed by .+ different macro"]),
452 medium('Empty loop body',
453 [r".*: warning: .+ loop has empty body"]),
454 medium('Implicit conversion from enumeration type',
455 [r".*: warning: implicit conversion from enumeration type '.+'"]),
456 medium('case value not in enumerated type',
457 [r".*: warning: case value not in enumerated type '.+'"]),
458 medium('Use of deprecated method',
459 [r".*: warning: '.+' is deprecated .+"]),
460 medium('Use of garbage or uninitialized value',
461 [r".*: warning: .+ uninitialized .+\[-Wsometimes-uninitialized\]"]),
462 medium('Sizeof on array argument',
463 [r".*: warning: sizeof on array function parameter will return"]),
464 medium('Bad argument size of memory access functions',
465 [r".*: warning: .+\[-Wsizeof-pointer-memaccess\]"]),
466 medium('Return value not checked',
467 [r".*: warning: The return value from .+ is not checked"]),
468 medium('Possible heap pollution',
469 [r".*: warning: .*Possible heap pollution from .+ type .+"]),
470 medium('Variable used in loop condition not modified in loop body',
471 [r".*: warning: variable '.+' used in loop condition.*Wfor-loop-analysis"]),
472 medium('Closing a previously closed file',
473 [r".*: warning: Closing a previously closed file"]),
474 medium('Unnamed template type argument',
475 [r".*: warning: template argument.+Wunnamed-type-template-args"]),
476 medium('Unannotated fall-through between switch labels',
477 [r".*: warning: unannotated fall-through between switch labels.+Wimplicit-fallthrough"]),
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800478 medium('Invalid partial specialization',
479 [r".*: warning: class template partial specialization.+Winvalid-partial-specialization"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700480 medium('Overlapping comparisons',
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800481 [r".*: warning: overlapping comparisons.+Wtautological-overlap-compare"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700482 medium('bitwise comparison',
483 [r".*: warning: bitwise comparison.+Wtautological-bitwise-compare"]),
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800484 medium('int in bool context',
485 [r".*: warning: converting.+to a boolean.+Wint-in-bool-context"]),
486 medium('bitwise conditional parentheses',
487 [r".*: warning: operator.+has lower precedence.+Wbitwise-conditional-parentheses"]),
488 medium('sizeof array div',
489 [r".*: warning: .+number of elements in.+array.+Wsizeof-array-div"]),
490 medium('bool operation',
491 [r".*: warning: .+boolean.+always.+Wbool-operation"]),
492 medium('Undefined bool conversion',
493 [r".*: warning: .+may be.+always.+true.+Wundefined-bool-conversion"]),
494 medium('Typedef requires a name',
495 [r".*: warning: typedef requires a name.+Wmissing-declaration"]),
496 medium('Unknown escape sequence',
497 [r".*: warning: unknown escape sequence.+Wunknown-escape-sequence"]),
498 medium('Unicode whitespace',
499 [r".*: warning: treating Unicode.+as whitespace.+Wunicode-whitespace"]),
500 medium('Unused local typedef',
501 [r".*: warning: unused typedef.+Wunused-local-typedef"]),
502 medium('varargs warnings',
503 [r".*: warning: .*argument to 'va_start'.+\[-Wvarargs\]"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800504 harmless('Discarded qualifier from pointer target type',
505 [r".*: warning: .+ discards '.+' qualifier from pointer target type"]),
506 harmless('Use snprintf instead of sprintf',
507 [r".*: warning: .*sprintf is often misused; please use snprintf"]),
508 harmless('Unsupported optimizaton flag',
509 [r".*: warning: optimization flag '.+' is not supported"]),
510 harmless('Extra or missing parentheses',
511 [r".*: warning: equality comparison with extraneous parentheses",
512 r".*: warning: .+ within .+Wlogical-op-parentheses"]),
513 harmless('Mismatched class vs struct tags',
514 [r".*: warning: '.+' defined as a .+ here but previously declared as a .+mismatched-tags",
515 r".*: warning: .+ was previously declared as a .+mismatched-tags"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800516]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800517
518
519def compile_patterns(patterns):
520 """Precompiling every pattern speeds up parsing by about 30x."""
521 for i in patterns:
522 i['compiled_patterns'] = []
523 for pat in i['patterns']:
524 i['compiled_patterns'].append(re.compile(pat))
525
526
527compile_patterns(warn_patterns)