Configuring the Visual Studio compiler as static analyzer

It is possible to use the Visual Studio compiler as a code checker (static analyzer) for C, C++ and C#. This means that the compiler warning level is set to maximum and any compiler warnings are stored in the quality database as violations. This makes it possible to track and reduce compiler warnings over time in a controlled manner.

Configuration

A default configuration for compiler warnings is provided by TICS in the configuration directory (in cfg/compilerwarnings). For C/C++, the analyzer VC is used, for C#, Csc.

By default, all warnings are reported (the maximum Visual Studio warning level is used).

Overriding the defaults

To configure warnings, one must specify the rule ID both in IMPL.txt and RULES.txt (just as for coding standard rules).

Example IMPL.txt

C++4057	VC	C4057
C4057	VC	C4057
C++4746	VC	C4746
C4746	VC	C4746

Here, the first three colums are relevant. The fourth column is not (yet) used. (For the moment, it is recommended to repeat the rule ID here.) The first three columns specify the rule ID (Visual Studio warning code), the language for which it should override the defaults and the analyzer tool 'VC'.

Example RULES.txt

C++4127	5	Visual Studio Severe Compiler Warning	A conditional expression should not be constant.
C4127	5	Visual Studio Severe Compiler Warning	A conditional expression should not be constant.
C++4706	7	Visual Studio Compiler Warning		Avoid side-effects in conditional expressions.
C4706	7	Visual Studio Compiler Warning		Avoid side-effects in conditional expressions.

Here, all aspects of the warning can be modified except for its ID (i.e., level, category and synopsis).

Warning reference

See the MSDN C/C++ Building Reference for a list of all compiler warnings.

Guiding compilation

Sometimes it is necessary to guide the C# compilation since the Visual Studio C# project build integration is not perfect. To help find the required .NET assemblies, additional search directories can be specified via an environment variable TICS_NET_ASSEMBLY_PATH. The syntax is similar to other search path variables: a list of directories separated by semicolons (';).

Example

set TICS_NET_ASSEMBLY_PATH=C:\app\tiobe\product\11.2.0\client_2\odp.net\bin\2.x;C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies;C:\Program Files (x86)\SunGard\AvantGard\4.4\Browser\Quantum;C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\win32_x86