blob: 1e1aa43fd5c9641800919a1696bc74b62d82ad03 [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 Hsieh3bb6c942021-09-23 13:48:34 -070096 medium('Set but not used',
97 [r".*: warning: .* set but not used.*Wunused-but-set"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -080098 medium('Unused parameter',
99 [r".*: warning: unused parameter '.*'"]),
100 medium('Unused function, variable, label, comparison, etc.',
101 [r".*: warning: '.+' defined but not used",
102 r".*: warning: unused function '.+'",
103 r".*: warning: unused label '.+'",
104 r".*: warning: relational comparison result unused",
105 r".*: warning: lambda capture .* is not used",
106 r".*: warning: private field '.+' is not used",
107 r".*: warning: unused variable '.+'"]),
108 medium('Statement with no effect or result unused',
109 [r".*: warning: statement with no effect",
110 r".*: warning: expression result unused"]),
111 medium('Ignoreing return value of function',
112 [r".*: warning: ignoring return value of function .+Wunused-result"]),
113 medium('Missing initializer',
114 [r".*: warning: missing initializer"]),
115 medium('Need virtual destructor',
116 [r".*: warning: delete called .* has virtual functions but non-virtual destructor"]),
117 skip('skip, near initialization for ...',
118 [r".*: warning: \(near initialization for '.+'\)"]),
119 medium('Expansion of data or time macro',
120 [r".*: warning: expansion of date or time macro is not reproducible"]),
121 medium('Macro expansion has undefined behavior',
122 [r".*: warning: macro expansion .* has undefined behavior"]),
123 medium('Format string does not match arguments',
124 [r".*: warning: format '.+' expects type '.+', but argument [0-9]+ has type '.+'",
125 r".*: warning: more '%' conversions than data arguments",
126 r".*: warning: data argument not used by format string",
127 r".*: warning: incomplete format specifier",
128 r".*: warning: unknown conversion type .* in format",
129 r".*: warning: format .+ expects .+ but argument .+Wformat=",
130 r".*: warning: field precision should have .+ but argument has .+Wformat",
131 r".*: warning: format specifies type .+ but the argument has .*type .+Wformat"]),
132 medium('Too many arguments for format string',
133 [r".*: warning: too many arguments for format"]),
134 medium('Too many arguments in call',
135 [r".*: warning: too many arguments in call to "]),
136 medium('Invalid format specifier',
137 [r".*: warning: invalid .+ specifier '.+'.+format-invalid-specifier"]),
138 medium('Comparison between signed and unsigned',
139 [r".*: warning: comparison between signed and unsigned",
140 r".*: warning: comparison of promoted \~unsigned with unsigned",
141 r".*: warning: signed and unsigned type in conditional expression"]),
142 medium('Comparison between enum and non-enum',
143 [r".*: warning: enumeral and non-enumeral type in conditional expression"]),
144 medium('libpng: zero area',
145 [r".*libpng warning: Ignoring attempt to set cHRM RGB triangle with zero area"]),
146 medium('Missing braces around initializer',
147 [r".*: warning: missing braces around initializer.*"]),
148 harmless('No newline at end of file',
149 [r".*: warning: no newline at end of file"]),
150 harmless('Missing space after macro name',
151 [r".*: warning: missing whitespace after the macro name"]),
152 low('Cast increases required alignment',
153 [r".*: warning: cast from .* to .* increases required alignment .*"]),
154 medium('Qualifier discarded',
155 [r".*: warning: passing argument [0-9]+ of '.+' discards qualifiers from pointer target type",
156 r".*: warning: assignment discards qualifiers from pointer target type",
157 r".*: warning: passing .+ to parameter of type .+ discards qualifiers",
158 r".*: warning: assigning to .+ from .+ discards qualifiers",
159 r".*: warning: initializing .+ discards qualifiers .+types-discards-qualifiers",
160 r".*: warning: return discards qualifiers from pointer target type"]),
161 medium('Unknown attribute',
162 [r".*: warning: unknown attribute '.+'"]),
163 medium('Attribute ignored',
164 [r".*: warning: '_*packed_*' attribute ignored",
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700165 r".*: warning: .* not supported .*Wignored-attributes",
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800166 r".*: warning: attribute declaration must precede definition .+ignored-attributes"]),
167 medium('Visibility problem',
168 [r".*: warning: declaration of '.+' will not be visible outside of this function"]),
169 medium('Visibility mismatch',
170 [r".*: warning: '.+' declared with greater visibility than the type of its field '.+'"]),
171 medium('Shift count greater than width of type',
172 [r".*: warning: (left|right) shift count >= width of type"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700173 medium('Shift operator precedence',
174 [r".*: warning: operator .* has lower precedence .+Wshift-op-parentheses.+"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800175 medium('extern <foo> is initialized',
176 [r".*: warning: '.+' initialized and declared 'extern'",
177 r".*: warning: 'extern' variable has an initializer"]),
178 medium('Old style declaration',
179 [r".*: warning: 'static' is not at beginning of declaration"]),
180 medium('Missing return value',
181 [r".*: warning: control reaches end of non-void function"]),
182 medium('Implicit int type',
183 [r".*: warning: type specifier missing, defaults to 'int'",
184 r".*: warning: type defaults to 'int' in declaration of '.+'"]),
185 medium('Main function should return int',
186 [r".*: warning: return type of 'main' is not 'int'"]),
187 medium('Variable may be used uninitialized',
188 [r".*: warning: '.+' may be used uninitialized in this function"]),
189 high('Variable is used uninitialized',
190 [r".*: warning: '.+' is used uninitialized in this function",
191 r".*: warning: variable '.+' is uninitialized when used here"]),
192 medium('ld: possible enum size mismatch',
193 [r".*: warning: .* uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail"]),
194 medium('Pointer targets differ in signedness',
195 [r".*: warning: pointer targets in initialization differ in signedness",
196 r".*: warning: pointer targets in assignment differ in signedness",
197 r".*: warning: pointer targets in return differ in signedness",
198 r".*: warning: pointer targets in passing argument [0-9]+ of '.+' differ in signedness"]),
199 medium('Assuming overflow does not occur',
200 [r".*: warning: assuming signed overflow does not occur when assuming that .* is always (true|false)"]),
201 medium('Suggest adding braces around empty body',
202 [r".*: warning: suggest braces around empty body in an 'if' statement",
203 r".*: warning: empty body in an if-statement",
204 r".*: warning: suggest braces around empty body in an 'else' statement",
205 r".*: warning: empty body in an else-statement"]),
206 medium('Suggest adding parentheses',
207 [r".*: warning: suggest explicit braces to avoid ambiguous 'else'",
208 r".*: warning: suggest parentheses around arithmetic in operand of '.+'",
209 r".*: warning: suggest parentheses around comparison in operand of '.+'",
210 r".*: warning: logical not is only applied to the left hand side of this comparison",
211 r".*: warning: using the result of an assignment as a condition without parentheses",
212 r".*: warning: .+ has lower precedence than .+ be evaluated first .+Wparentheses",
213 r".*: warning: suggest parentheses around '.+?' .+ '.+?'",
214 r".*: warning: suggest parentheses around assignment used as truth value"]),
215 medium('Static variable used in non-static inline function',
216 [r".*: warning: '.+' is static but used in inline function '.+' which is not static"]),
217 medium('No type or storage class (will default to int)',
218 [r".*: warning: data definition has no type or storage class"]),
219 skip('skip, parameter name (without types) in function declaration',
220 [r".*: warning: parameter names \(without types\) in function declaration"]),
221 medium('Dereferencing <foo> breaks strict aliasing rules',
222 [r".*: warning: dereferencing .* break strict-aliasing rules"]),
223 medium('Cast from pointer to integer of different size',
224 [r".*: warning: cast from pointer to integer of different size",
225 r".*: warning: initialization makes pointer from integer without a cast"]),
226 medium('Cast to pointer from integer of different size',
227 [r".*: warning: cast to pointer from integer of different size"]),
228 medium('Macro redefined',
229 [r".*: warning: '.+' macro redefined"]),
230 skip('skip, ... location of the previous definition',
231 [r".*: warning: this is the location of the previous definition"]),
232 medium('ld: type and size of dynamic symbol are not defined',
233 [r".*: warning: type and size of dynamic symbol `.+' are not defined"]),
234 medium('Pointer from integer without cast',
235 [r".*: warning: assignment makes pointer from integer without a cast"]),
236 medium('Pointer from integer without cast',
237 [r".*: warning: passing argument [0-9]+ of '.+' makes pointer from integer without a cast"]),
238 medium('Integer from pointer without cast',
239 [r".*: warning: assignment makes integer from pointer without a cast"]),
240 medium('Integer from pointer without cast',
241 [r".*: warning: passing argument [0-9]+ of '.+' makes integer from pointer without a cast"]),
242 medium('Integer from pointer without cast',
243 [r".*: warning: return makes integer from pointer without a cast"]),
244 medium('Ignoring pragma',
245 [r".*: warning: ignoring #pragma .+"]),
246 medium('Pragma warning messages',
247 [r".*: warning: .+W#pragma-messages"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700248 medium('Pragma once in main file',
249 [r".*: warning: #pragma once in main file .+Wpragma-once-outside-header.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800250 medium('Variable might be clobbered by longjmp or vfork',
251 [r".*: warning: variable '.+' might be clobbered by 'longjmp' or 'vfork'"]),
252 medium('Argument might be clobbered by longjmp or vfork',
253 [r".*: warning: argument '.+' might be clobbered by 'longjmp' or 'vfork'"]),
254 medium('Redundant declaration',
255 [r".*: warning: redundant redeclaration of '.+'"]),
256 skip('skip, previous declaration ... was here',
257 [r".*: warning: previous declaration of '.+' was here"]),
258 high('Enum value not handled in switch',
259 [r".*: warning: .*enumeration value.* not handled in switch.+Wswitch"]),
260 medium('User defined warnings',
261 [r".*: warning: .* \[-Wuser-defined-warnings\]$"]),
262 medium('Taking address of temporary',
263 [r".*: warning: taking address of temporary"]),
264 medium('Taking address of packed member',
265 [r".*: warning: taking address of packed member"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700266 medium('Pack alignment value is modified',
267 [r".*: warning: .*#pragma pack alignment value is modified.*Wpragma-pack.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800268 medium('Possible broken line continuation',
269 [r".*: warning: backslash and newline separated by space"]),
270 medium('Undefined variable template',
271 [r".*: warning: instantiation of variable .* no definition is available"]),
272 medium('Inline function is not defined',
273 [r".*: warning: inline function '.*' is not defined"]),
274 medium('Excess elements in initializer',
275 [r".*: warning: excess elements in .+ initializer"]),
276 medium('Decimal constant is unsigned only in ISO C90',
277 [r".*: warning: this decimal constant is unsigned only in ISO C90"]),
278 medium('main is usually a function',
279 [r".*: warning: 'main' is usually a function"]),
280 medium('Typedef ignored',
281 [r".*: warning: 'typedef' was ignored in this declaration"]),
282 high('Address always evaluates to true',
283 [r".*: warning: the address of '.+' will always evaluate as 'true'"]),
284 fixmenow('Freeing a non-heap object',
285 [r".*: warning: attempt to free a non-heap object '.+'"]),
286 medium('Array subscript has type char',
287 [r".*: warning: array subscript .+ type 'char'.+Wchar-subscripts"]),
288 medium('Constant too large for type',
289 [r".*: warning: integer constant is too large for '.+' type"]),
290 medium('Constant too large for type, truncated',
291 [r".*: warning: large integer implicitly truncated to unsigned type"]),
292 medium('Overflow in expression',
293 [r".*: warning: overflow in expression; .*Winteger-overflow"]),
294 medium('Overflow in implicit constant conversion',
295 [r".*: warning: overflow in implicit constant conversion"]),
296 medium('Declaration does not declare anything',
297 [r".*: warning: declaration 'class .+' does not declare anything"]),
298 medium('Initialization order will be different',
299 [r".*: warning: '.+' will be initialized after",
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700300 r".*: warning: initializer order does not match the declaration order",
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800301 r".*: warning: field .+ will be initialized after .+Wreorder"]),
302 skip('skip, ....',
303 [r".*: warning: '.+'"]),
304 skip('skip, base ...',
305 [r".*: warning: base '.+'"]),
306 skip('skip, when initialized here',
307 [r".*: warning: when initialized here"]),
308 medium('Parameter type not specified',
309 [r".*: warning: type of '.+' defaults to 'int'"]),
310 medium('Missing declarations',
311 [r".*: warning: declaration does not declare anything"]),
312 medium('Missing noreturn',
313 [r".*: warning: function '.*' could be declared with attribute 'noreturn'"]),
314 medium('User warning',
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -0700315 [r".*: warning: #warning \".+\""]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800316 medium('Vexing parsing problem',
317 [r".*: warning: empty parentheses interpreted as a function declaration"]),
318 medium('Dereferencing void*',
319 [r".*: warning: dereferencing 'void \*' pointer"]),
320 medium('Comparison of pointer and integer',
321 [r".*: warning: ordered comparison of pointer with integer zero",
322 r".*: warning: .*comparison between pointer and integer"]),
323 medium('Use of error-prone unary operator',
324 [r".*: warning: use of unary operator that may be intended as compound assignment"]),
325 medium('Conversion of string constant to non-const char*',
326 [r".*: warning: deprecated conversion from string constant to '.+'"]),
327 medium('Function declaration isn''t a prototype',
328 [r".*: warning: function declaration isn't a prototype"]),
329 medium('Type qualifiers ignored on function return value',
330 [r".*: warning: type qualifiers ignored on function return type",
331 r".*: warning: .+ type qualifier .+ has no effect .+Wignored-qualifiers"]),
332 medium('<foo> declared inside parameter list, scope limited to this definition',
333 [r".*: warning: '.+' declared inside parameter list"]),
334 skip('skip, its scope is only this ...',
335 [r".*: warning: its scope is only this definition or declaration, which is probably not what you want"]),
336 low('Line continuation inside comment',
337 [r".*: warning: multi-line comment"]),
338 low('Comment inside comment',
339 [r".*: warning: '.+' within block comment .*-Wcomment"]),
340 low('Deprecated declarations',
341 [r".*: warning: .+ is deprecated.+deprecated-declarations"]),
342 low('Deprecated register',
343 [r".*: warning: 'register' storage class specifier is deprecated"]),
344 low('Converts between pointers to integer types with different sign',
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700345 [r".*: warning: .+ converts between pointers to integer types .+Wpointer-sign\]"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800346 harmless('Extra tokens after #endif',
347 [r".*: warning: extra tokens at end of #endif directive"]),
348 medium('Comparison between different enums',
349 [r".*: warning: comparison between '.+' and '.+'.+Wenum-compare",
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700350 r".*: warning: comparison of .* enumeration types .*-Wenum-compare.*"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800351 medium('Conversion may change value',
352 [r".*: warning: converting negative value '.+' to '.+'",
353 r".*: warning: conversion to '.+' .+ may (alter|change)"]),
354 medium('Converting to non-pointer type from NULL',
355 [r".*: warning: converting to non-pointer type '.+' from NULL"]),
356 medium('Implicit sign conversion',
357 [r".*: warning: implicit conversion changes signedness"]),
358 medium('Converting NULL to non-pointer type',
359 [r".*: warning: implicit conversion of NULL constant to '.+'"]),
360 medium('Zero used as null pointer',
361 [r".*: warning: expression .* zero treated as a null pointer constant"]),
362 medium('Compare pointer to null character',
363 [r".*: warning: comparing a pointer to a null character constant"]),
364 medium('Implicit conversion changes value or loses precision',
365 [r".*: warning: implicit conversion .* changes value from .* to .*-conversion",
366 r".*: warning: implicit conversion loses integer precision:"]),
367 medium('Passing NULL as non-pointer argument',
368 [r".*: warning: passing NULL to non-pointer argument [0-9]+ of '.+'"]),
369 medium('Class seems unusable because of private ctor/dtor',
370 [r".*: warning: all member functions in class '.+' are private"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800371 # skip this next one, because it only points out some RefBase-based classes
372 # where having a private destructor is perfectly fine
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800373 skip('Class seems unusable because of private ctor/dtor',
374 [r".*: warning: 'class .+' only defines a private destructor and has no friends"]),
375 medium('Class seems unusable because of private ctor/dtor',
376 [r".*: warning: 'class .+' only defines private constructors and has no friends"]),
377 medium('In-class initializer for static const float/double',
378 [r".*: warning: in-class initializer for static data member of .+const (float|double)"]),
379 medium('void* used in arithmetic',
380 [r".*: warning: pointer of type 'void \*' used in (arithmetic|subtraction)",
381 r".*: warning: arithmetic on .+ to void is a GNU extension.*Wpointer-arith",
382 r".*: warning: wrong type argument to increment"]),
383 medium('Overload resolution chose to promote from unsigned or enum to signed type',
384 [r".*: warning: passing '.+' chooses '.+' over '.+'.*Wsign-promo"]),
385 skip('skip, in call to ...',
386 [r".*: warning: in call to '.+'"]),
387 high('Base should be explicitly initialized in copy constructor',
388 [r".*: warning: base class '.+' should be explicitly initialized in the copy constructor"]),
389 medium('Return value from void function',
390 [r".*: warning: 'return' with a value, in function returning void"]),
391 medium('Multi-character character constant',
392 [r".*: warning: multi-character character constant"]),
393 medium('Conversion from string literal to char*',
394 [r".*: warning: .+ does not allow conversion from string literal to 'char \*'"]),
395 low('Extra \';\'',
396 [r".*: warning: extra ';' .+extra-semi"]),
397 low('Useless specifier',
398 [r".*: warning: useless storage class specifier in empty declaration"]),
399 low('Duplicate declaration specifier',
400 [r".*: warning: duplicate '.+' declaration specifier"]),
401 low('Comparison of self is always false',
402 [r".*: self-comparison always evaluates to false"]),
403 low('Logical op with constant operand',
404 [r".*: use of logical '.+' with constant operand"]),
405 low('Needs a space between literal and string macro',
406 [r".*: warning: invalid suffix on literal.+ requires a space .+Wliteral-suffix"]),
407 low('Warnings from #warning',
408 [r".*: warning: .+-W#warnings"]),
409 low('Using float/int absolute value function with int/float argument',
410 [r".*: warning: using .+ absolute value function .+ when argument is .+ type .+Wabsolute-value",
411 r".*: warning: absolute value function '.+' given .+ which may cause truncation .+Wabsolute-value"]),
412 low('Using C++11 extensions',
413 [r".*: warning: 'auto' type specifier is a C\+\+11 extension"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700414 low('Using C++17 extensions',
415 [r".*: warning: .* a C\+\+17 extension .+Wc\+\+17-extensions"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800416 low('Refers to implicitly defined namespace',
417 [r".*: warning: using directive refers to implicitly-defined namespace .+"]),
418 low('Invalid pp token',
419 [r".*: warning: missing .+Winvalid-pp-token"]),
420 low('need glibc to link',
421 [r".*: warning: .* requires at runtime .* glibc .* for linking"]),
Chih-Hung Hsieh5d9ee042021-06-01 16:03:22 -0700422 low('Add braces to avoid dangling else',
423 [r".*: warning: add explicit braces to avoid dangling else"]),
424 low('Assigning value to self',
425 [r".*: warning: explicitly assigning value of .+ to itself"]),
426 low('Comparison of integers of different signs',
427 [r".*: warning: comparison of integers of different signs.+sign-compare"]),
428 low('Incompatible pointer types',
429 [r".*: warning: incompatible .*pointer types .*-Wincompatible-.*pointer-types"]),
430 low('Missing braces',
431 [r".*: warning: suggest braces around initialization of",
432 r".*: warning: too many braces around scalar initializer .+Wmany-braces-around-scalar-init",
433 r".*: warning: braces around scalar initializer"]),
434 low('Missing field initializers',
435 [r".*: warning: missing field '.+' initializer"]),
436 low('Typedef redefinition',
437 [r".*: warning: redefinition of typedef '.+' is a C11 feature"]),
438 low('GNU old-style field designator',
439 [r".*: warning: use of GNU old-style field designator extension"]),
440 low('Initializer overrides prior initialization',
441 [r".*: warning: initializer overrides prior initialization of this subobject"]),
442 low('GNU extension, variable sized type not at end',
443 [r".*: warning: field '.+' with variable sized type '.+' not at the end of a struct or class"]),
444 low('Comparison of constant is always false/true',
445 [r".*: comparison of .+ is always .+Wtautological-constant-out-of-range-compare"]),
446 low('Hides overloaded virtual function',
447 [r".*: '.+' hides overloaded virtual function"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800448 medium('Operator new returns NULL',
449 [r".*: warning: 'operator new' must not return NULL unless it is declared 'throw\(\)' .+"]),
450 medium('NULL used in arithmetic',
451 [r".*: warning: NULL used in arithmetic",
Chih-Hung Hsiehf36e01d2021-10-08 13:14:41 -0700452 r".*: warning: .* subtraction with a null pointer",
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800453 r".*: warning: comparison between NULL and non-pointer"]),
454 medium('Misspelled header guard',
455 [r".*: warning: '.+' is used as a header guard .+ followed by .+ different macro"]),
456 medium('Empty loop body',
457 [r".*: warning: .+ loop has empty body"]),
458 medium('Implicit conversion from enumeration type',
459 [r".*: warning: implicit conversion from enumeration type '.+'"]),
460 medium('case value not in enumerated type',
461 [r".*: warning: case value not in enumerated type '.+'"]),
462 medium('Use of deprecated method',
463 [r".*: warning: '.+' is deprecated .+"]),
464 medium('Use of garbage or uninitialized value',
465 [r".*: warning: .+ uninitialized .+\[-Wsometimes-uninitialized\]"]),
466 medium('Sizeof on array argument',
467 [r".*: warning: sizeof on array function parameter will return"]),
468 medium('Bad argument size of memory access functions',
469 [r".*: warning: .+\[-Wsizeof-pointer-memaccess\]"]),
470 medium('Return value not checked',
471 [r".*: warning: The return value from .+ is not checked"]),
472 medium('Possible heap pollution',
473 [r".*: warning: .*Possible heap pollution from .+ type .+"]),
474 medium('Variable used in loop condition not modified in loop body',
475 [r".*: warning: variable '.+' used in loop condition.*Wfor-loop-analysis"]),
476 medium('Closing a previously closed file',
477 [r".*: warning: Closing a previously closed file"]),
478 medium('Unnamed template type argument',
479 [r".*: warning: template argument.+Wunnamed-type-template-args"]),
480 medium('Unannotated fall-through between switch labels',
481 [r".*: warning: unannotated fall-through between switch labels.+Wimplicit-fallthrough"]),
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800482 medium('Invalid partial specialization',
483 [r".*: warning: class template partial specialization.+Winvalid-partial-specialization"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700484 medium('Overlapping comparisons',
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800485 [r".*: warning: overlapping comparisons.+Wtautological-overlap-compare"]),
Chih-Hung Hsiehe8f4a712020-09-18 21:51:06 -0700486 medium('bitwise comparison',
487 [r".*: warning: bitwise comparison.+Wtautological-bitwise-compare"]),
Chih-Hung Hsiehb09530b2020-01-29 11:01:36 -0800488 medium('int in bool context',
489 [r".*: warning: converting.+to a boolean.+Wint-in-bool-context"]),
490 medium('bitwise conditional parentheses',
491 [r".*: warning: operator.+has lower precedence.+Wbitwise-conditional-parentheses"]),
492 medium('sizeof array div',
493 [r".*: warning: .+number of elements in.+array.+Wsizeof-array-div"]),
494 medium('bool operation',
495 [r".*: warning: .+boolean.+always.+Wbool-operation"]),
496 medium('Undefined bool conversion',
497 [r".*: warning: .+may be.+always.+true.+Wundefined-bool-conversion"]),
498 medium('Typedef requires a name',
499 [r".*: warning: typedef requires a name.+Wmissing-declaration"]),
500 medium('Unknown escape sequence',
501 [r".*: warning: unknown escape sequence.+Wunknown-escape-sequence"]),
502 medium('Unicode whitespace',
503 [r".*: warning: treating Unicode.+as whitespace.+Wunicode-whitespace"]),
504 medium('Unused local typedef',
505 [r".*: warning: unused typedef.+Wunused-local-typedef"]),
506 medium('varargs warnings',
507 [r".*: warning: .*argument to 'va_start'.+\[-Wvarargs\]"]),
Chih-Hung Hsieh8724ff72020-01-13 11:02:15 -0800508 harmless('Discarded qualifier from pointer target type',
509 [r".*: warning: .+ discards '.+' qualifier from pointer target type"]),
510 harmless('Use snprintf instead of sprintf',
511 [r".*: warning: .*sprintf is often misused; please use snprintf"]),
512 harmless('Unsupported optimizaton flag',
513 [r".*: warning: optimization flag '.+' is not supported"]),
514 harmless('Extra or missing parentheses',
515 [r".*: warning: equality comparison with extraneous parentheses",
516 r".*: warning: .+ within .+Wlogical-op-parentheses"]),
517 harmless('Mismatched class vs struct tags',
518 [r".*: warning: '.+' defined as a .+ here but previously declared as a .+mismatched-tags",
519 r".*: warning: .+ was previously declared as a .+mismatched-tags"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800520]
Chih-Hung Hsieh949205a2020-01-10 10:33:40 -0800521
522
523def compile_patterns(patterns):
524 """Precompiling every pattern speeds up parsing by about 30x."""
525 for i in patterns:
526 i['compiled_patterns'] = []
527 for pat in i['patterns']:
528 i['compiled_patterns'].append(re.compile(pat))
529
530
531compile_patterns(warn_patterns)