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