manual, help text: updates of --enable text. updates of 'Preprocessor configurations' section, the --force and --max-configs can be used together with -D.

This commit is contained in:
Daniel Marjamäki 2013-06-09 10:34:45 +02:00
parent 616a693f1f
commit c65437c74c
2 changed files with 85 additions and 92 deletions

View File

@ -743,8 +743,10 @@ void CmdLineParser::PrintHelp()
" by providing an implementation for them.\n" " by providing an implementation for them.\n"
" --check-config Check cppcheck configuration. The normal code\n" " --check-config Check cppcheck configuration. The normal code\n"
" analysis is disabled by this flag.\n" " analysis is disabled by this flag.\n"
" -D<ID> By default Cppcheck checks all configurations. Use -D\n" " -D<ID> By default Cppcheck checks all configurations. When -D\n"
" to limit the checking to a particular configuration.\n" " is used, Cppcheck only checks the given configuration.\n"
" But you can also use --force or --max-configs to check\n"
" multiple configurations.\n"
" Example: '-DDEBUG=1 -D__cplusplus'.\n" " Example: '-DDEBUG=1 -D__cplusplus'.\n"
" -U<ID> By default Cppcheck checks all configurations. Use -U\n" " -U<ID> By default Cppcheck checks all configurations. Use -U\n"
" to explicitly hide certain #ifdef <ID> code paths from\n" " to explicitly hide certain #ifdef <ID> code paths from\n"
@ -753,6 +755,8 @@ void CmdLineParser::PrintHelp()
" --enable=<id> Enable additional checks. The available ids are:\n" " --enable=<id> Enable additional checks. The available ids are:\n"
" * all\n" " * all\n"
" Enable all checks\n" " Enable all checks\n"
" * warning\n"
" Enable warning messages"
" * style\n" " * style\n"
" Enable all coding style checks. All messages\n" " Enable all coding style checks. All messages\n"
" with the severities 'style', 'performance' and\n" " with the severities 'style', 'performance' and\n"

View File

@ -104,9 +104,10 @@ Checking path/file2.cpp...
<para>All files under <filename class="directory">src/a</filename> and <para>All files under <filename class="directory">src/a</filename> and
<filename class="directory">src/b</filename> are then checked.</para> <filename class="directory">src/b</filename> are then checked.</para>
<para>The second option is to use <parameter class="command">-i</parameter>, <para>The second option is to use <parameter
with it you specify files/paths to ignore. With this command no files in class="command">-i</parameter>, with it you specify files/paths to
<filename class="directory">src/c</filename> are checked:</para> ignore. With this command no files in <filename
class="directory">src/c</filename> are checked:</para>
<programlisting>cppcheck -isrc/c src</programlisting> <programlisting>cppcheck -isrc/c src</programlisting>
</section> </section>
@ -147,9 +148,10 @@ Checking path/file2.cpp...
<term>performance</term> <term>performance</term>
<listitem> <listitem>
<para>Suggestions for making the code faster. These suggestions are <para>Suggestions for making the code faster. These suggestions
only based on common knowledge. It is not certain you'll get any are only based on common knowledge. It is not certain you'll get
measurable difference in speed by fixing these messages.</para> any measurable difference in speed by fixing these
messages.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
@ -175,67 +177,42 @@ Checking path/file2.cpp...
<section> <section>
<title>Enable messages</title> <title>Enable messages</title>
<para>By default only <parameter class="command">error</parameter> messages <para>By default only <parameter class="command">error</parameter>
are shown. Through the <parameter class="command">--enable</parameter> messages are shown. Through the <parameter
command more checks can be enabled.</para> class="command">--enable</parameter> command more checks can be
enabled.</para>
<section> <programlisting># enable warning messages
<title>Stylistic issues</title> cppcheck --enable=warning file.c
<para>With <parameter class="command">--enable=style</parameter> you # enable performance messages
enable most <parameter class="command">warning</parameter>, cppcheck --enable=performance file.c
<parameter class="command">style</parameter> and
<parameter class="command">performance</parameter> messages.</para>
<para>Here is a simple code example:</para> # enable information messages
cppcheck --enable=information file.c
<programlisting>void f(int x) # For historical reasons, --enable=style enables warning, performance,
{ # portability and style messages. These are all reported as "style" when
int i; # using the old xml format.
if (x == 0) cppcheck --enable=style file.c
{
i = 0;
}
}</programlisting>
<para>There are no bugs in that code so Cppcheck won't report anything # enable warning and information messages
by default. To enable the stylistic messages, use the cppcheck --enable=warning,information file.c
<parameter class="command">--enable=style</parameter> command:</para>
<programlisting>cppcheck --enable=style file3.c</programlisting> # enable unusedFunction checking. This is not enabled by --enable=style
# because it doesn't work well on libraries.
cppcheck --enable=unusedFunction file.c
<para>The output from Cppcheck is now:</para> # enable all messages
cppcheck --enable=all</programlisting>
<programlisting>Checking file3.c...
[file3.c:3]: (style) Variable 'i' is assigned a value that is never used
[file3.c:3]: (style) The scope of the variable i can be reduced</programlisting>
</section>
<section>
<title>Unused functions</title>
<para>This check will try to find unused functions. It is best to use
this when the whole program is checked, so that all usages is seen by
cppcheck.</para>
<programlisting>cppcheck --enable=unusedFunction path</programlisting>
</section>
<section>
<title>Enable all checks</title>
<para>To enable all checks your can use the
<parameter class="command">--enable=all</parameter> flag:</para>
<programlisting>cppcheck --enable=all path</programlisting>
</section>
<section> <section>
<title>Inconclusive checks</title> <title>Inconclusive checks</title>
<para>By default Cppcheck only writes error messages if it is certain. <para>By default Cppcheck only writes error messages if it is certain.
With <parameter class="command">--inconclusive</parameter> error With <parameter class="command">--inconclusive</parameter> error
messages will also be written when the analysis is inconclusive.</para> messages will also be written when the analysis is
inconclusive.</para>
<programlisting>cppcheck --inconclusive path</programlisting> <programlisting>cppcheck --inconclusive path</programlisting>
@ -258,8 +235,9 @@ Checking path/file2.cpp...
<section> <section>
<title>Multithreaded checking</title> <title>Multithreaded checking</title>
<para>The option -j is used to specify the number of threads you want to use. <para>The option -j is used to specify the number of threads you want to
For example, to use 4 threads to check the files in a folder:</para> use. For example, to use 4 threads to check the files in a
folder:</para>
<programlisting>cppcheck -j 4 path</programlisting> <programlisting>cppcheck -j 4 path</programlisting>
</section> </section>
@ -269,22 +247,30 @@ Checking path/file2.cpp...
<title>Preprocessor configurations</title> <title>Preprocessor configurations</title>
<para>By default Cppcheck will check all preprocessor configurations <para>By default Cppcheck will check all preprocessor configurations
(except those that have #error in them). This is the recommended (except those that have #error in them).</para>
behaviour.</para>
<para>But if you want to manually limit the checking you can do so with <para>You can use -D to change this. When you use -D, cppcheck will by
<parameter class="command">-D</parameter>.</para> default only check the given configuration and nothing else. This is how
compilers work. But you can use <literal>--force</literal> or
<literal><literal>--max-configs</literal></literal> to override the number
of configurations.</para>
<para>Beware that only the macros, which are given here and the macros <programlisting># check all configurations
defined in source files and known header files are considered. That cppcheck file.c
excludes all the macros defined in some system header files, which are by
default not examined by Cppcheck.</para>
<para>The usage: if you, for example, want to limit the checking so the # only check the configuration A
only configuration to check should be <literal>DEBUG=1;__cplusplus</literal> cppcheck -DA file.c
then something like this can be used:</para>
<programlisting>cppcheck -DDEBUG=1 -D__cplusplus path</programlisting> # check all configurations when macro A is defined
cppcheck -DA --force file.c</programlisting>
<para>Another useful flag might be -U. It undefines a symbol. Example
usage:</para>
<programlisting>cppcheck -UX file.c</programlisting>
<para>That will mean that X is not defined. Cppcheck will not check what
happens when X is defined.</para>
</chapter> </chapter>
<chapter> <chapter>
@ -416,8 +402,8 @@ Checking path/file2.cpp...
<para>If you want to reformat the output so it looks different you can use <para>If you want to reformat the output so it looks different you can use
templates.</para> templates.</para>
<para>To get Visual Studio compatible output you can use <para>To get Visual Studio compatible output you can use <parameter
<parameter class="command">--template=vs</parameter>:</para> class="command">--template=vs</parameter>:</para>
<programlisting>cppcheck --template=vs gui/test.cpp</programlisting> <programlisting>cppcheck --template=vs gui/test.cpp</programlisting>
@ -427,8 +413,8 @@ Checking path/file2.cpp...
gui/test.cpp(31): error: Memory leak: b gui/test.cpp(31): error: Memory leak: b
gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting> gui/test.cpp(16): error: Mismatching allocation and deallocation: k</programlisting>
<para>To get gcc compatible output you can use <para>To get gcc compatible output you can use <parameter
<parameter class="command">--template=gcc</parameter>:</para> class="command">--template=gcc</parameter>:</para>
<programlisting>cppcheck --template=gcc gui/test.cpp</programlisting> <programlisting>cppcheck --template=gcc gui/test.cpp</programlisting>
@ -449,7 +435,8 @@ gui/test.cpp:16: error: Mismatching allocation and deallocation: k</programlisti
gui/test.cpp,31,error,memleak,Memory leak: b gui/test.cpp,31,error,memleak,Memory leak: b
gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocation: k</programlisting> gui/test.cpp,16,error,mismatchAllocDealloc,Mismatching allocation and deallocation: k</programlisting>
<para>The escape sequences \b (backspace), \n (newline), \r (formfeed) and \t (horizontal tab) are supported.</para> <para>The escape sequences \b (backspace), \n (newline), \r (formfeed) and
\t (horizontal tab) are supported.</para>
</chapter> </chapter>
<chapter> <chapter>
@ -558,9 +545,8 @@ Checking test.c...
<section> <section>
<title>User-defined allocation/deallocation functions</title> <title>User-defined allocation/deallocation functions</title>
<para>Cppcheck understands standard allocation and <para>Cppcheck understands standard allocation and deallocation
deallocation functions. But it doesn't know what library functions functions. But it doesn't know what library functions do.</para>
do.</para>
<para>Here is example code that might leak memory or resources:</para> <para>Here is example code that might leak memory or resources:</para>
@ -591,8 +577,8 @@ void DestroyFred(void *p)
}</programlisting> }</programlisting>
<para>When Cppcheck see this it understands that <function>CreateFred() <para>When Cppcheck see this it understands that <function>CreateFred()
</function> will return allocated memory and that <function>DestroyFred() </function> will return allocated memory and that
</function> will deallocate memory.</para> <function>DestroyFred() </function> will deallocate memory.</para>
<para>Now, execute <command>cppcheck</command> this way:</para> <para>Now, execute <command>cppcheck</command> this way:</para>
@ -609,11 +595,11 @@ void DestroyFred(void *p)
<title>HTML report</title> <title>HTML report</title>
<para>You can convert the XML output from cppcheck into a HTML report. <para>You can convert the XML output from cppcheck into a HTML report.
You'll need Python and the pygments module You'll need Python and the pygments module (<ulink
(<ulink url="http://pygments.org/">http://pygments.org/</ulink>) for this to url="http://pygments.org/">http://pygments.org/</ulink>) for this to work.
work. In the Cppcheck source tree there is a folder In the Cppcheck source tree there is a folder <filename
<filename class="directory">htmlreport</filename> that contains a script class="directory">htmlreport</filename> that contains a script that
that transforms a Cppcheck XML file into HTML output.</para> transforms a Cppcheck XML file into HTML output.</para>
<para>This command generates the help screen:</para> <para>This command generates the help screen:</para>
@ -675,8 +661,10 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.<
<para>The language can be changed at any time by using the <para>The language can be changed at any time by using the
<guimenu>Language</guimenu> menu.</para> <guimenu>Language</guimenu> menu.</para>
<para>More settings are available in <para>More settings are available in <menuchoice>
<menuchoice><guimenu>Edit</guimenu><guimenuitem>Preferences</guimenuitem> <guimenu>Edit</guimenu>
<guimenuitem>Preferences</guimenuitem>
</menuchoice>.</para> </menuchoice>.</para>
</section> </section>
@ -696,9 +684,10 @@ htmlreport/cppcheck-htmlreport --file=err.xml --report-dir=test1 --source-dir=.<
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<para>As you can read in <link linkend="preprocessor-configurations">chapter <para>As you can read in <link
3</link> in this manual the default is that Cppcheck checks all configurations. linkend="preprocessor-configurations">chapter 3</link> in this manual
So only provide preprocessor defines if you want to limit the checking.</para> the default is that Cppcheck checks all configurations. So only provide
preprocessor defines if you want to limit the checking.</para>
</section> </section>
</chapter> </chapter>
</book> </book>