C++ Static Analysis Improvements for Visual Studio 2017 15.6 Preview 2

Kyle Reed

点这里看中文版

We’ve made a few changes to the C++ static analysis feature that should make it faster and easier to use. The behavior has changed slightly, and the menus have been moved around a bit, but we think that the new experience is faster and more consistent. Let’s take a quick look at the changes.

Single File Analysis

Developers tend to focus on a few files at a time when working on code. To make it easier to get analysis results for the files you’re editing, you can now run code analysis on a single file. This lets you get code analysis warnings without having to rebuild the entire project. We think this will be especially useful when fixing analysis warnings because it makes it convenient to check and recheck a file. After analysis runs, all analysis warnings for the file will appear in the error list.

Screenshot of single file analysis.
New build menu item to run C++ code analysis on a single file.

 

Screenshot showing single file analysis results.
Code Analysis results for a single file.

If you have a few files you want to check, you can also select multiple files in the Solution Explorer and run code analysis on only those files.

Screenshot showing the code analysis menu for multiple selected files.
Multiple files selected in the Solution Explorer can be analyzed at once.

More Consistent Menus

To make the code analysis menus easier to find, we’ve made them more consistent with their “Build” counterparts. In previous versions, you would find the menu to run code analysis on a project under the “Project Only” menu. Now the menus to start analysis on a solution, project, or file are located near their “Build X” counterpart on the “Build” menu. On the Solution Explorer context menus, look for the “Analyze” menu on the solution, project, and file nodes of the tree.

Build Menu

Screenshot showing the location of new analysis menus on the top Build menu.
New build menu locations for starting solution, project, and per-file code analysis.

Context Menus

Screenshot showing new Solution Explorer context menus for starting analysis.
New Solution Explorer context menus for running solution, project or per-file code analysis.

Analyze Only

We’ve heard from developers that running code analysis takes too long. In previous versions, running code analysis required a full build and link before analysis would run. Now when you run code analysis, we no longer generate code or link. This dramatically reduces analysis run time.

One side effect is that you will no longer see some build warnings during analysis runs. You will get build warnings during builds, and code analysis warnings during analysis runs. If you prefer to see build and analysis warnings at the same time, check the “Enable Code Analysis on Build” box in the project properties and rebuild your project.

Screenshot showing how to enable Code Analysis on Build.
Enable Code Analysis on Build to get build and analysis results at the same time.

C++ Core Guidelines Checker

C++ Core Check is currently not enabled by default, so if you want to try out the new single-file analysis experience with C++ Core Check, the extension must first be enabled on the project.

Screenshot showing C++ Core Check extension enabled for a project.
The C++ Core Check extension has to be enabled per-project if you want the C++ Core Check results when you run code analysis.

Wrap Up

These are just a few simple tweaks to improve the C++ code analysis experience. Download the latest Visual Studio preview and give them a try. We hope you will find it easier to use on your projects and that the tools help you write safer, more modern C++.

As always, we welcome your feedback. Feel free to send any comments through e-mail at visualcpp@microsoft.com, through Twitter @visualc, or Facebook at Microsoft Visual Cpp.

If you encounter other problems with MSVC in VS 2017 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. For suggestions, let us know through UserVoice. Thank you!

Happy coding.

0 comments

Discussion is closed.

Feedback usabilla icon