-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cppcheck
More file actions
352 lines (312 loc) · 11.6 KB
/
example.cppcheck
File metadata and controls
352 lines (312 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?xml version="1.0" encoding="UTF-8"?>
<!-- cppcheck has a GUI component that outputs XML config files, which can
then be passed to the CLI with `--project=`. When automating use of
cppcheck, for example as an integrated cmake linter, it could be desirable
to hand-write these config files. However, their format is not documented,
and examples are hard to find, see:
- https://stackoverflow.com/a/69311493
This file is provided as both an example and documentation of the available
XML tags. It was produced by analysis of the cppcheck v2.11 source,
especially ImportProject::importCppcheckGuiProject:
- https://github.com/danmar/cppcheck/blob/2.11/lib/importproject.cpp#L1127
and its comparison with CmdLineParser::parseFromArgs:
- https://github.com/danmar/cppcheck/blob/2.11/cli/cmdlineparser.cpp#L143
Command line options with corresponding XML tags:
--addon=
--clang
--cppcheck-build-dir=
-D
--file-list=
-i
-I --includes-file=
--library
--max-ctu-depth
--platform=
--project
-rp= / --relative-paths=
--suppress= / --suppressions-list=
-U
For most tags that share settings with a CLI option, parsing the project
file will nullify any of those options set in the command line before
passing `--project=`, so best practice is to call the options after parsing
the project file. For example, with a config file test.cppcheck that
contains:
<defines>
<define name="DEF1"></define>
<define name="DEF2"></define>
</defines>
and a CLI line like:
cppcheck --project=config.cppcheck -DDEF3 -DDEF4 test.cc
DEF1, DEF2, DEF3, and DEF4 will be defined in the preprocessor, but with:
cppcheck -DDEF3 -DDEF4 --project=config.cppcheck test.cc
only DEF1 and DEF2 will be. Refer to descriptions of each tag for exact
interactions.
-->
<!-- XML needs to have a root node. Node name is arbitrary and has no effect in
cppcheck; consider defaulting to cmake project or target name for which
linting will be configured.
-->
<project>
<!-- each subnode text appends to a list which replaces settings.addons
(corresponds to `--addon=`)
-->
<addons>
<addon></addon>
</addons>
<!-- node text sets settings.project.guiProject.analyzeAllVsConfigs
(GUI exclusive)
-->
<analyze-all-vs-configs></analyze-all-vs-configs>
<!-- node text sets settings.buildDir
(corresponds to `--cppcheck-build-dir=`)
-->
<builddir></builddir>
<!-- node text of exactly "true" sets settings.checkHeaders == true, any other
text sets to false
(GUI exclusive)
-->
<check-headers></check-headers>
<!-- node text of exactly "true" sets settings.checkUnusedTemplates == true,
any other text sets to false
(GUI exclusive)
-->
<check-unused-templates></check-unused-templates>
<!-- each subnode name attribute appends to a list which replaces
settings.userDefines. note that one can only set a macro as defined,
not assign it a definition as with `-D=`.
(corresponds to `-D`)
-->
<defines>
<define name=""></define>
</defines>
<!-- each subnode name attribute appends to settings.project.guiProject.excludedPaths,
which are later appended to mIgnoredPaths in reverse order (back inserted)
(corresponds to `-i`)
-->
<exclude>
<path name=""></path>
</exclude>
<!-- each subnode name attribute appends to settings.project.guiProject.excludedPaths,
which are later appended to mIgnoredPaths in reverse order (back inserted)
(corresponds to `-i`)
(same as <exclude>)
-->
<ignore>
<path name=""></path>
</ignore>
<!-- node text, if not empty, sets settings.project.guiProject.projectFile,
which causes separate import of another project file after the one
processed with `--project`
(corresponds to `--project`)
-->
<importproject></importproject>
<!-- each subnode name attribute appends to a list which replaces
settings.includePaths
(corresponds to `-I`, `--includes-file=`)
-->
<includedir>
<dir name=""></dir>
</includedir>
<!-- each subnode text appends to settings.project.guiProject.libraries, which
are later appended to settings.libraries
(corresponds to `--library`)
-->
<libraries>
<library></library>
</libraries>
<!-- node text sets settings.maxCtuDepth
(expects text that converts to int)
(empty text defaults to "2")
(corresponds to `--max-ctu-depth`)
-->
<max-ctu-depth></max-ctu-depth>
<!-- node text sets settings.maxTemplateRecursion
(expects text that converts to int)
(empty text defaults to "100")
(GUI exclusive)
-->
<max-template-recursion></max-template-recursion>
<!-- sets settings.clang == true regardless of node text; note that
settings.clangExecutable cannot be set as with `--clang=`
(corresponds to `--clang`)
-->
<parser></parser>
<!-- each subnode name attribute appends to settings.project.guiProject.pathNames,
which replaces mPathNames
(corresponds to `--file-list=`)
-->
<paths>
<dir name=""></dir>
</paths>
<!-- relative path of non-empty name attribute appended to settings.basePaths,
settings.relativePaths set to true
(corresponds to `-rp=`)
-->
<root name=""></root>
<!-- node text sets settings.project.guiProject.platform, which replaces
settings.platform - automatically if valid string:
win32A win32W win64
unix32 unix64
native
unspecified
or via parsing a platform XML file found in the following paths, with
dir = directory of file passed with `--project=` or cppcheck binary,
and filename = settings.project.guiProject.platform
<filename>
<filename>.xml
platforms/<filename>
platforms/<filename>.xml
<dir><filename>
<dir>platforms/<filename>
<dir>platforms/<filename>.xml
XML example (remove comments):
"""
<?xml version="1.0" encoding="UTF-8"?>
<platform>
<default-sign></default-sign> # node text set to platform.defaultSign
<char_bit></char_bit> # node text uint set to platform.char_bit
<sizeof>
<short></short> # node text uint sets platform.sizeof_short
<bool></bool> # node text uint sets platform.sizeof_bool
<int></int> # node text uint sets platform.sizeof_int
<long></long> # node text uint sets platform.sizeof_long
<long-long></long-long> # node text uint sets platform.sizeof_long_long
<float></float> # node text uint sets platform.sizeof_float
<double></double> # node text uint sets platform.sizeof_double
<long-double></long-double> # node text uint sets platform.sizeof_long_double
<pointer></pointer> # node text uint sets platform.sizeof_pointer
<size_t></size_t> # node text uint sets platform.sizeof_size_t
<wchar_t></wchar_t> # node text uint sets platform.sizeof_wchar_t
</sizeof>
</platform>
"""
see:
- https://github.com/danmar/cppcheck/blob/2.11/lib/platform.cpp#L160
(corresponds to `--platform=`)
-->
<platform></platform>
<!-- (GUI exclusive)
-->
<safe-checks>
<!-- sets settings.safeChecks.classes == true regardless of node text
-->
<class-public></class-public>
<!-- sets settings.safeChecks.externalFunctions == true regardless of node text
-->
<external-functions></external-functions>
<!-- sets settings.safeChecks.internalFunctions == true regardless of node text
-->
<internal-functions></internal-functions>
<!-- sets settings.safeChecks.externalVariables == true regardless of node text
-->
<external-variables></external-variables>
</safe-checks>
<!-- each subnode appends a supression to a list which replaces settings.nomsg:
(corresponds to `--suppress=` or `--suppressions-list=`; symbolName and
hash are GUI exclusives)
-->
<suppressions>
<!-- subnode populated Suppression members:
errorId = subnode text
fileName = subnode fileName attribute
lineNumber = subnode lineNumber attribute, or -1 if empty
symbolName = subnode symbolName attribute
hash = subnode hash attribute, or 0 if empty
-->
<suppression
fileName="" lineNumber="" symbolName="" hash=""
></suppression>
</suppressions>
<tools>
<!-- tool subnode text of "clang-tidy" sets settings.clangTidy == true; all
subnode text ignored
-->
<tool></tool>
</tools>
<!-- each subnode text inserts into a set of undefines which replaces
settings.userUndefs
(corresponds to `-U`)
-->
<undefines>
<undefine></undefine>
</undefines>
<!-- each subnode text appends to settings.project.guiProject.checkVsConfigs
(GUI exclusive)
-->
<vs-configurations>
<config></config>
</vs-configurations>
<!-- no-ops
(GUI exclusive)
-->
<!--
<check-unknown-function-return-values></check-unknown-function-return-values>
<function-contracts></function-contracts>
<tags tag=""></tags>
<tag-warnings></tag-warnings>
<variable-contracts></variable-contracts>
-->
<!-- cppcheck premium features
-->
<!--
<bug-hunting></bug-hunting>
<cert-c-int-precision></cert-c-int-precision>
<coding-standards>
<coding-standards></coding-standards>
</coding-standards>
-->
</project>
<!--
Documented options exclusive to CLI:
--check-config
--check-level=normal|exhaustive
--check-library
--clang= (xml can set clang to true, but not set clangExecutable)
--config-exclude=
--config-excludes-file=
--disable
--enable
--errorlist
--error-exitcode=
--exitcode-suppressions=
--file-filter=
--force
--include=
--inconclusive
--inline-suppr
-j
--language=c|c++, -x
--max-configs=
--output-file=
--platform=
--plist-output=
--premium= # undocumented
--project=
--project-configuration=
--quiet, -q
--report-progress
--rule=
--rule-file=
--std=
--template=''
--template-location=''
--verbose, -v
--xml
--xml-version=
Undocumented options exclusive to CLI (discovered during source analysis):
--checks-max-time= # sets settings.checksMaxTime
--debug|--debug-normal # settings.debugnormal = true;
--debug-simplified # settings.debugSimplified = true;
--debug-template # settings.debugtemplate = true;
--debug-warnings # settings.debugwarnings = true;
--doc # prints descriptions of checks
--dump # sets settings.dump = true
--exception-handling # sets settings.exceptionHandling = true
--exception-handling=stdout|stderr # sets CppCheckExecutor::mExceptionOutput
-l # sets int to settings.loadAverage
--premium= # adds to settings.premiumArgs
--showtime=file|file-total|summary|top5|"" # sets settings.showtime
--template-max-time= # sets settings.templateMaxTime
--typedef-max-time= # sets settings.typedefMaxTime
--valueflow-max-iterations= # sets settings.valueFlowMaxIterations
-->