I am working on a C++ library and I'd like to enable Visual Studio's static analysis for it. To get familiar with it, I've read through these articles and started this walkthrough. However, in both my project and the walkthrough demo project, I cannot get the analysis to work inside of Visual Studio. Specifically, in these steps from the walkthrough:
In Solution Explorer, select the CodeDefects project.
On the Project menu, click Properties.
Click Code Analysis.
Click the Enable Code Analysis for C/C++ on Build check box.
I don't see the check box from step 6. My dialog looks like this:
Furthermore, running this command line (for the demo):
cl /analyze .\Bug.cpp
produces several code analysis warnings, but executing code analysis on the solution in Visual Studio (Analyze, Run Code Analysis, On Solution) shows no warnings at all in the error list.
What am I missing here?
Here is my MVCE, pared down from the walkthrough:
Using Visual Studio 2015 Professional Update 2, create an empty C++ project.
Change the project's Configuration Type to "Static Library".
Right-click on the project's properties, select Code Analysis, then check the box for "Enable Code Analysis on Build" and select "Microsoft All Rules" for the current platform/configuration or all.
Create "Bug.cpp" and set its contents to this:
int path_dependent(int n) { int i; int j; if (n == 0) i = 1; else j = 1; return i + j; }
Build the project. Observe no errors for C6001 in the Error List.
At a developer prompt, run the command
cl /analyze:only .\Bug.cpp
and observe the expected errors:Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23918 for x86 Copyright (C) Microsoft Corporation. All rights reserved. Bug.cpp c:\sources\cppdemo\codedefectsdemo\bug.cpp(9) : warning C6001: Using uninitialized memory 'i'.: Lines: 3, 4, 5, 8, 9 c:\sources\cppdemo\codedefectsdemo\bug.cpp(9) : warning C6001: Using uninitialized memory 'j'.: Lines: 3, 4, 5, 6, 9