Skip to content

Commit c65437c

Browse files
committed
manual, help text: updates of --enable text. updates of 'Preprocessor configurations' section, the --force and --max-configs can be used together with -D.
1 parent 616a693 commit c65437c

2 files changed

Lines changed: 85 additions & 92 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,10 @@ void CmdLineParser::PrintHelp()
743743
" by providing an implementation for them.\n"
744744
" --check-config Check cppcheck configuration. The normal code\n"
745745
" analysis is disabled by this flag.\n"
746-
" -D<ID> By default Cppcheck checks all configurations. Use -D\n"
747-
" to limit the checking to a particular configuration.\n"
746+
" -D<ID> By default Cppcheck checks all configurations. When -D\n"
747+
" is used, Cppcheck only checks the given configuration.\n"
748+
" But you can also use --force or --max-configs to check\n"
749+
" multiple configurations.\n"
748750
" Example: '-DDEBUG=1 -D__cplusplus'.\n"
749751
" -U<ID> By default Cppcheck checks all configurations. Use -U\n"
750752
" to explicitly hide certain #ifdef <ID> code paths from\n"
@@ -753,6 +755,8 @@ void CmdLineParser::PrintHelp()
753755
" --enable=<id> Enable additional checks. The available ids are:\n"
754756
" * all\n"
755757
" Enable all checks\n"
758+
" * warning\n"
759+
" Enable warning messages"
756760
" * style\n"
757761
" Enable all coding style checks. All messages\n"
758762
" with the severities 'style', 'performance' and\n"

man/manual.docbook

Lines changed: 79 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ Checking path/file2.cpp...
104104
<para>All files under <filename class="directory">src/a</filename> and
105105
<filename class="directory">src/b</filename> are then checked.</para>
106106

107-
<para>The second option is to use <parameter class="command">-i</parameter>,
108-
with it you specify files/paths to ignore. With this command no files in
109-
<filename class="directory">src/c</filename> are checked:</para>
107+
<para>The second option is to use <parameter
108+
class="command">-i</parameter>, with it you specify files/paths to
109+
ignore. With this command no files in <filename
110+
class="directory">src/c</filename> are checked:</para>
110111

111112
<programlisting>cppcheck -isrc/c src</programlisting>
112113
</section>
@@ -147,9 +148,10 @@ Checking path/file2.cpp...
147148
<term>performance</term>
148149

149150
<listitem>
150-
<para>Suggestions for making the code faster. These suggestions are
151-
only based on common knowledge. It is not certain you'll get any
152-
measurable difference in speed by fixing these messages.</para>
151+
<para>Suggestions for making the code faster. These suggestions
152+
are only based on common knowledge. It is not certain you'll get
153+
any measurable difference in speed by fixing these
154+
messages.</para>
153155
</listitem>
154156
</varlistentry>
155157

@@ -175,67 +177,42 @@ Checking path/file2.cpp...
175177
<section>
176178
<title>Enable messages</title>
177179

178-
<para>By default only <parameter class="command">error</parameter> messages
179-
are shown. Through the <parameter class="command">--enable</parameter>
180-
command more checks can be enabled.</para>
180+
<para>By default only <parameter class="command">error</parameter>
181+
messages are shown. Through the <parameter
182+
class="command">--enable</parameter> command more checks can be
183+
enabled.</para>
181184

182-
<section>
183-
<title>Stylistic issues</title>
184-
185-
<para>With <parameter class="command">--enable=style</parameter> you
186-
enable most <parameter class="command">warning</parameter>,
187-
<parameter class="command">style</parameter> and
188-
<parameter class="command">performance</parameter> messages.</para>
189-
190-
<para>Here is a simple code example:</para>
191-
192-
<programlisting>void f(int x)
193-
{
194-
int i;
195-
if (x == 0)
196-
{
197-
i = 0;
198-
}
199-
}</programlisting>
185+
<programlisting># enable warning messages
186+
cppcheck --enable=warning file.c
200187

201-
<para>There are no bugs in that code so Cppcheck won't report anything
202-
by default. To enable the stylistic messages, use the
203-
<parameter class="command">--enable=style</parameter> command:</para>
188+
# enable performance messages
189+
cppcheck --enable=performance file.c
204190

205-
<programlisting>cppcheck --enable=style file3.c</programlisting>
191+
# enable information messages
192+
cppcheck --enable=information file.c
206193

207-
<para>The output from Cppcheck is now:</para>
194+
# For historical reasons, --enable=style enables warning, performance,
195+
# portability and style messages. These are all reported as "style" when
196+
# using the old xml format.
197+
cppcheck --enable=style file.c
208198

209-
<programlisting>Checking file3.c...
210-
[file3.c:3]: (style) Variable 'i' is assigned a value that is never used
211-
[file3.c:3]: (style) The scope of the variable i can be reduced</programlisting>
212-
</section>
199+
# enable warning and information messages
200+
cppcheck --enable=warning,information file.c
213201

214-
<section>
215-
<title>Unused functions</title>
202+
# enable unusedFunction checking. This is not enabled by --enable=style
203+
# because it doesn't work well on libraries.
204+
cppcheck --enable=unusedFunction file.c
216205

217-
<para>This check will try to find unused functions. It is best to use
218-
this when the whole program is checked, so that all usages is seen by
219-
cppcheck.</para>
220-
221-
<programlisting>cppcheck --enable=unusedFunction path</programlisting>
222-
</section>
223-
224-
<section>
225-
<title>Enable all checks</title>
226-
227-
<para>To enable all checks your can use the
228-
<parameter class="command">--enable=all</parameter> flag:</para>
229-
230-
<programlisting>cppcheck --enable=all path</programlisting>
231-
</section>
206+
# enable all messages
207+
cppcheck --enable=all</programlisting>
232208

233209
<section>
234210
<title>Inconclusive checks</title>
235211

236212
<para>By default Cppcheck only writes error messages if it is certain.
237213
With <parameter class="command">--inconclusive</parameter> error
238-
messages will also be written when the analysis is inconclusive.</para>
214+
messages will also be written when the analysis is
215+
inconclusive.</para>
239216

240217
<programlisting>cppcheck --inconclusive path</programlisting>
241218

@@ -258,8 +235,9 @@ Checking path/file2.cpp...
258235
<section>
259236
<title>Multithreaded checking</title>
260237

261-
<para>The option -j is used to specify the number of threads you want to use.
262-
For example, to use 4 threads to check the files in a folder:</para>
238+
<para>The option -j is used to specify the number of threads you want to
239+
use. For example, to use 4 threads to check the files in a
240+
folder:</para>
263241

264242
<programlisting>cppcheck -j 4 path</programlisting>
265243
</section>
@@ -269,22 +247,30 @@ Checking path/file2.cpp...
269247
<title>Preprocessor configurations</title>
270248

271249
<para>By default Cppcheck will check all preprocessor configurations
272-
(except those that have #error in them). This is the recommended
273-
behaviour.</para>
250+
(except those that have #error in them).</para>
274251

275-
<para>But if you want to manually limit the checking you can do so with
276-
<parameter class="command">-D</parameter>.</para>
252+
<para>You can use -D to change this. When you use -D, cppcheck will by
253+
default only check the given configuration and nothing else. This is how
254+
compilers work. But you can use <literal>--force</literal> or
255+
<literal><literal>--max-configs</literal></literal> to override the number
256+
of configurations.</para>
277257

278-
<para>Beware that only the macros, which are given here and the macros
279-
defined in source files and known header files are considered. That
280-
excludes all the macros defined in some system header files, which are by
281-
default not examined by Cppcheck.</para>
258+
<programlisting># check all configurations
259+
cppcheck file.c
282260

283-
<para>The usage: if you, for example, want to limit the checking so the
284-
only configuration to check should be <literal>DEBUG=1;__cplusplus</literal>
285-
then something like this can be used:</para>
261+
# only check the configuration A
262+
cppcheck -DA file.c
286263

287-
<programlisting>cppcheck -DDEBUG=1 -D__cplusplus path</programlisting>
264+
# check all configurations when macro A is defined
265+
cppcheck -DA --force file.c</programlisting>
266+
267+
<para>Another useful flag might be -U. It undefines a symbol. Example
268+
usage:</para>
269+
270+
<programlisting>cppcheck -UX file.c</programlisting>
271+
272+
<para>That will mean that X is not defined. Cppcheck will not check what
273+
happens when X is defined.</para>
288274
</chapter>
289275

290276
<chapter>
@@ -403,7 +389,7 @@ Checking path/file2.cpp...
403389

404390
<listitem>
405391
<para>this attribute doesn't exist yet. But in the future we may
406-
add a short message for each location. </para>
392+
add a short message for each location.</para>
407393
</listitem>
408394
</varlistentry>
409395
</variablelist>
@@ -416,8 +402,8 @@ Checking path/file2.cpp...
416402
<para>If you want to reformat the output so it looks different you can use
417403
templates.</para>
418404

419-
<para>To get Visual Studio compatible output you can use
420-
<parameter class="command">--template=vs</parameter>:</para>
405+
<para>To get Visual Studio compatible output you can use <parameter
406+
class="command">--template=vs</parameter>:</para>
421407

422408
<programlisting>cppcheck --template=vs gui/test.cpp</programlisting>
423409

@@ -427,8 +413,8 @@ Checking path/file2.cpp...
427413
gui/test.cpp(31): error: Memory leak: b
428414
gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting>
429415

430-
<para>To get gcc compatible output you can use
431-
<parameter class="command">--template=gcc</parameter>:</para>
416+
<para>To get gcc compatible output you can use <parameter
417+
class="command">--template=gcc</parameter>:</para>
432418

433419
<programlisting>cppcheck --template=gcc gui/test.cpp</programlisting>
434420

@@ -449,7 +435,8 @@ gui/test.cpp:16: error: Mismatching allocation and deallocation: k</programlisti
449435
gui/test.cpp,31,error,memleak,Memory leak: b
450436
gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocation: k</programlisting>
451437

452-
<para>The escape sequences \b (backspace), \n (newline), \r (formfeed) and \t (horizontal tab) are supported.</para>
438+
<para>The escape sequences \b (backspace), \n (newline), \r (formfeed) and
439+
\t (horizontal tab) are supported.</para>
453440
</chapter>
454441

455442
<chapter>
@@ -558,9 +545,8 @@ Checking test.c...
558545
<section>
559546
<title>User-defined allocation/deallocation functions</title>
560547

561-
<para>Cppcheck understands standard allocation and
562-
deallocation functions. But it doesn't know what library functions
563-
do.</para>
548+
<para>Cppcheck understands standard allocation and deallocation
549+
functions. But it doesn't know what library functions do.</para>
564550

565551
<para>Here is example code that might leak memory or resources:</para>
566552

@@ -591,8 +577,8 @@ void DestroyFred(void *p)
591577
}</programlisting>
592578

593579
<para>When Cppcheck see this it understands that <function>CreateFred()
594-
</function> will return allocated memory and that <function>DestroyFred()
595-
</function> will deallocate memory.</para>
580+
</function> will return allocated memory and that
581+
<function>DestroyFred() </function> will deallocate memory.</para>
596582

597583
<para>Now, execute <command>cppcheck</command> this way:</para>
598584

@@ -609,11 +595,11 @@ void DestroyFred(void *p)
609595
<title>HTML report</title>
610596

611597
<para>You can convert the XML output from cppcheck into a HTML report.
612-
You'll need Python and the pygments module
613-
(<ulink url="http://pygments.org/">http://pygments.org/</ulink>) for this to
614-
work. In the Cppcheck source tree there is a folder
615-
<filename class="directory">htmlreport</filename> that contains a script
616-
that transforms a Cppcheck XML file into HTML output.</para>
598+
You'll need Python and the pygments module (<ulink
599+
url="http://pygments.org/">http://pygments.org/</ulink>) for this to work.
600+
In the Cppcheck source tree there is a folder <filename
601+
class="directory">htmlreport</filename> that contains a script that
602+
transforms a Cppcheck XML file into HTML output.</para>
617603

618604
<para>This command generates the help screen:</para>
619605

@@ -675,9 +661,11 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.<
675661
<para>The language can be changed at any time by using the
676662
<guimenu>Language</guimenu> menu.</para>
677663

678-
<para>More settings are available in
679-
<menuchoice><guimenu>Edit</guimenu><guimenuitem>Preferences</guimenuitem>
680-
</menuchoice>.</para>
664+
<para>More settings are available in <menuchoice>
665+
<guimenu>Edit</guimenu>
666+
667+
<guimenuitem>Preferences</guimenuitem>
668+
</menuchoice>.</para>
681669
</section>
682670

683671
<section>
@@ -696,9 +684,10 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.<
696684
</listitem>
697685
</itemizedlist>
698686

699-
<para>As you can read in <link linkend="preprocessor-configurations">chapter
700-
3</link> in this manual the default is that Cppcheck checks all configurations.
701-
So only provide preprocessor defines if you want to limit the checking.</para>
687+
<para>As you can read in <link
688+
linkend="preprocessor-configurations">chapter 3</link> in this manual
689+
the default is that Cppcheck checks all configurations. So only provide
690+
preprocessor defines if you want to limit the checking.</para>
702691
</section>
703692
</chapter>
704693
</book>

0 commit comments

Comments
 (0)