{"id":18385,"date":"2018-03-13T11:13:31","date_gmt":"2018-03-13T18:13:31","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=18385"},"modified":"2019-02-18T17:48:01","modified_gmt":"2019-02-18T17:48:01","slug":"c-code-analysis-improvements-for-visual-studio-2017-15-7-preview-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/c-code-analysis-improvements-for-visual-studio-2017-15-7-preview-1\/","title":{"rendered":"C++ Code Analysis Improvements for Visual Studio 2017 15.7 Preview 1"},"content":{"rendered":"<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/c\/2018\/03\/22\/c\u4ee3\u7801\u5206\u6790\u5728visual-studio-2017-\u9884\u89c8\u72481-\u4e0a\u7684\u63d0\u9ad8\/\">\u70b9\u8fd9\u91cc\u770b\u4e2d\u6587\u7248<\/a><\/p>\n<p style=\"font-weight: 400\"><span>We&#8217;re making it easier to configure and use the C++ code analysis features with a set of changes targeting 15.7. In the first 15.7 preview we&#8217;ve cleaned up the UI, fixed our documentation links<\/span><span> and, most importantly, simplified the way analysis extensions are <\/span><span>configured.<\/span><span>\u00a0<\/span><\/p>\n<p>If you&#8217;re not familiar with C++ Core Check, it&#8217;s a code analysis extension that helps you update your code to be safer and use a more modern style as outlined in the <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md\">C++ Core Guidelines<\/a>. You can learn more about the rules we enforce on our <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/code-analysis-for-cpp-corecheck\">reference page<\/a>.<\/p>\n<h2 style=\"font-weight: 400\"><span>C++ Core Check Extension on by De<\/span><span>fault<\/span><\/h2>\n<p style=\"font-weight: 400\"><span>We wanted to make it easier for developers to take advantage of the new checks from C++ Core Check<\/span><span>. <\/span><span>Previously if developers wanted to use C++ Core Check with code analysis, they had to explicitly enable the analysis extension for each project. Then, when running analysis, the tools would produce a deluge of Core Check warnings because all C++ Core Check warnings were enabled by default.<\/span><span>\u00a0<\/span><\/p>\n<p style=\"font-weight: 400\"><span>Starting in Preview 1, the C++ Core Check extension is enabled whenever<\/span><span> code analysis <\/span><span>is run. We also updated the Microsoft Native Recommended Rules and Microsoft Native Minimum Rules to include only the highest impact C++ Core Check warnings (more on that below). We think this provides the best experience: running code analysis on a project &#8220;just works&#8221; without requiring additional configuration.<\/span><span>\u00a0<\/span><\/p>\n<p style=\"font-weight: 400\"><span>We also removed the UI that was used to configure the analysis extensions because it&#8217;s no longer needed. Our goal is to make the ruleset the one-stop configuration file for code analysis. All a developer needs to worry about is which warnings he or she wants to run, and the engine will intelligently enable and disable extensions and checkers based on the ruleset. <em>This feature isn&#8217;t fully implemented in Preview 1; the remaining work will ship in an upcoming preview.<\/em><\/span><span>\u00a0<\/span><\/p>\n<p><figure id=\"attachment_18395\" aria-labelledby=\"figcaption_attachment_18395\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/15_6_extensions_pane.png\"><img decoding=\"async\" width=\"1463\" height=\"1023\" class=\"size-full wp-image-18395\" alt=\"Screenshot showing the previous code analysis extension panel that was removed.\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/15_6_extensions_pane.png\" \/><\/a><figcaption id=\"figcaption_attachment_18395\" class=\"wp-caption-text\">The code analysis extensions selection panel has been removed &#8211; extensions will be enabled automatically based on the rules that are enabled.<\/figcaption><\/figure><\/p>\n<p><figure id=\"attachment_18405\" aria-labelledby=\"figcaption_attachment_18405\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/15_7_extensions_pane_removed.png\"><img decoding=\"async\" width=\"1231\" height=\"842\" class=\"size-full wp-image-18405\" alt=\"Screenshot showing that the extension panel was removed.\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/15_7_extensions_pane_removed.png\" \/><\/a><figcaption id=\"figcaption_attachment_18405\" class=\"wp-caption-text\">The code analysis extensions panel was removed from the project properties page in 15.7 preview 1.<\/figcaption><\/figure><\/p>\n<h3 style=\"font-weight: 400\"><span>Disabling C++ Core Check for a Project<\/span><\/h3>\n<p style=\"font-weight: 400\"><span>Because this work is still in preview, we added a way to revert to the previous behavior. If the C++ Core Check extension is causing problems with a project, it can be disabled per-project by editing the vcxproj file and adding the following property.<\/span><\/p>\n<pre style=\"font-weight: 400\"><span>\u00a0 &lt;<\/span><span>PropertyGroup<\/span><span>&gt;<\/span><span>\u00a0\n<\/span><span>\u00a0\u00a0\u00a0 &lt;<\/span><span>EnableCppCoreCheck<\/span><span>&gt;false&lt;\/<\/span><span>EnableCppCoreCheck<\/span><span>&gt;<\/span><span>\u00a0\n<\/span><span>\u00a0 &lt;\/<\/span><span>PropertyGroup<\/span><span>&gt;<\/span><span>\u00a0<\/span><\/pre>\n<p>When building from the command line with msbuild, it can also be disabled by passing the property <span style=\"font-family: monospace !important;font-weight: bold\">\/p:EnableCppCoreCheck=false<\/span><\/p>\n<p style=\"font-weight: 400\"><span>If you find you need to disable the extension, we&#8217;d like to know about any blocking issues you found. Use the &#8220;Send Feedback&#8221; button in Visual Studio to report any problems.<\/span><span>\u00a0<\/span><\/p>\n<h2 style=\"font-weight: 400\"><span>New Rules in Recommended and Minimum Rulesets<\/span><\/h2>\n<p style=\"font-weight: 400\"><span>Previously the Microsoft Native Recommended and Microsoft Minimum Rulesets had all C++ Core Check warnings <\/span><span>enabled <\/span><span>by default. This meant if you wanted to try out C++ Core Check and enabled the extension, you&#8217;d get a flood of additional warnings.<\/span><span>\u00a0<\/span><\/p>\n<p style=\"font-weight: 400\"><span>To stay consistent with the spirit of the &#8220;Recommended&#8221; and &#8220;Minimum&#8221; rulesets, we<\/span><span> looked across our internal projects and identified the C++ Core Check rules that helped prevent the most critical bugs. The Recommended and Minimum rulesets still contain the core analyzer rules they had previously and now also contain the high-impact C++ Core Check rules. If you want to run with all the C++ Core Check warnings enabled, you can still choose the &#8220;C++ Core Check Rules&#8221; ruleset.<\/span><span>\u00a0<\/span><\/p>\n<h3 style=\"font-weight: 400\"><span>New in Microsoft Native Minimum<\/span><span>\u00a0<\/span><\/h3>\n<ul>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26450\">C26450<\/a> RESULT_OF_ARITHMETIC_OPERATION_PROVABLY_LOSSY<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26451\">C26451<\/a> RESULT_OF_ARITHMETIC_OPERATION_CAST_TO_LARGER_SIZE<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26452\">C26452<\/a> SHIFT_COUNT_NEGATIVE_OR_TOO_BIG<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26453\">C26453<\/a> LEFTSHIFT_NEGATIVE_SIGNED_NUMBER<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26454\">C26454<\/a> RESULT_OF_ARITHMETIC_OPERATION_NEGATIVE_UNSIGNED<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/code-analysis-for-cpp-corecheck\">C26495<\/a> MEMBER_UNINIT<\/span><\/li>\n<\/ul>\n<h3 style=\"font-weight: 400\"><span>New in Microsoft Native Recommended<\/span><\/h3>\n<ul>\n<li><em>All the Minimum rules above<\/em><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26441\">C26441<\/a> NO_UNNAMED_GUARDS<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26444\">C26444<\/a> NO_UNNAMED_RAII_OBJECTS<\/span><\/li>\n<li><span><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/code-analysis-for-cpp-corecheck\">C26498<\/a> USE_CONSTEXPR_FOR_FUNCTIONCALL<\/span><\/li>\n<\/ul>\n<p><figure id=\"attachment_18415\" aria-labelledby=\"figcaption_attachment_18415\" class=\"wp-caption alignnone\" ><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/warning_c26498_examples.png\"><img decoding=\"async\" width=\"901\" height=\"463\" class=\"wp-image-18415 size-full\" alt=\"Screenshot of warning C26498 on sample code.\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/warning_c26498_examples.png\" \/><\/a><figcaption id=\"figcaption_attachment_18415\" class=\"wp-caption-text\">Simple example of warning C26498 from C++ Core Check.<\/figcaption><\/figure><\/p>\n<h2 style=\"font-weight: 400\"><span>C++ Core Check Experimental Extension Removed<\/span><span>\u00a0<\/span><\/h2>\n<p style=\"font-weight: 400\"><span>Previous versions of Visual Studio included a C++ Core Check (Experimental) option for rules that weren\u2019t quite ready for release. We&#8217;ve been updating these rules over several releases and now the rules dealing with raw pointers, owner pointers, and lifetime profile are implemented in the <\/span><span>main checker. A few of the experimental rules do not map exactly to new rules and are being deprecated.\u00a0 <\/span><span>\u00a0<\/span><\/p>\n<h3 style=\"font-weight: 400\"><span>The following experimental rules are deprecated<\/span><span>\u00a0<\/span><\/h3>\n<ul>\n<li><span>C26412 DEREF_INVALID_POINTER<\/span><\/li>\n<li><span>C26413 DEREF_NULLPTR<\/span><\/li>\n<li><span>C26420 ASSIGN_NONOWNER_TO_EXPLICIT_OWNER<\/span><\/li>\n<li><span>C26421 ASSIGN_VALID_OWNER<\/span><\/li>\n<li><span>C26422 VALID_OWNER_LEAVING_SCOPE<\/span><\/li>\n<li><span>C26423 ALLOCATION_NOT_ASSIGNED_TO_OWNER<\/span><\/li>\n<li><span>C26424 VALID_ALLOCATION_LEAVING_SCOPE<\/span><\/li>\n<li><span>C26425 ASSIGNING_TO_STATIC<\/span><\/li>\n<li><span>C26499 NO_LIFETIME_TRACKING<\/span><\/li>\n<\/ul>\n<h2 style=\"font-weight: 400\"><span>Fit and Finish<\/span><\/h2>\n<p style=\"font-weight: 400\"><span>We also spent some time fixing some minor bugs to improve the overall C++ code analysis experience.<\/span><span>\u00a0<\/span><\/p>\n<ul>\n<li><span>Clicking on an error navigates to the current documentation page instead of the page for previous versions of Visual Studio.<\/span><span>\u00a0<\/span><\/li>\n<li><span>Removed &#8220;Run Code Metrics&#8221; from the Analyze menu on projects that don&#8217;t support Code Metrics.<\/span><span>\u00a0<\/span><\/li>\n<li><span>C++ Core Check now runs significantly faster and uses up to 50% less memory compared with the 15.6 release.<\/span><\/li>\n<li>Added a hot key to run code analysis on the current file: <span style=\"font-family: monospace !important;background-color: #eee\">Ctrl+Shift+Alt+F7<\/span> in the default keyboard mapping.<\/li>\n<\/ul>\n<h2 style=\"font-weight: 400\"><span>Wrap Up<\/span><span>\u00a0<\/span><\/h2>\n<p style=\"font-weight: 400\"><span>We&#8217;re excited to have C++ Core Check on by default and a simpler story for getting our code analysis tools set up for your projects. Hopefully you&#8217;ll find the C++ code analysis tools easier to use and the new warnings useful.<\/span><span>\u00a0Download the latest\u00a0<a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio preview<\/a>\u00a0and give them a try.<\/span><\/p>\n<p style=\"font-weight: 400\"><span>As always, we welcome your feedback. Feel free to send any comments through e-mail at <\/span><a href=\"mailto:visualcpp@microsoft.com\"><span>visualcpp@microsoft.com<\/span><\/a><span>, through <a href=\"https:\/\/twitter.com\/visualc\">Twitter @<\/a><\/span><span>visualc<\/span><span>, or Facebook at <a href=\"https:\/\/www.facebook.com\/Microsoft-Visual-Cpp-222043184527264\/\">Microsoft Visual Cpp<\/a><\/span>.<span>\u00a0<\/span><\/p>\n<p style=\"font-weight: 400\"><span>If you encounter other problems with MSVC in VS 2017, please let us know via the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a> option, either from the installer or the Visual Studio IDE itself. For suggestions, let us know through <\/span><a href=\"https:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio-2015\/category\/30937-languages-c\"><span>UserVoice<\/span><\/a><span>. Thank you!<\/span><span>\u00a0<\/span><\/p>\n<p>Happy coding.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u70b9\u8fd9\u91cc\u770b\u4e2d\u6587\u7248 We&#8217;re making it easier to configure and use the C++ code analysis features with a set of changes targeting 15.7. In the first 15.7 preview we&#8217;ve cleaned up the UI, fixed our documentation links and, most importantly, simplified the way analysis extensions are configured.\u00a0 If you&#8217;re not familiar with C++ Core Check, it&#8217;s a [&hellip;]<\/p>\n","protected":false},"author":2869,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[239,277],"tags":[119,245,163],"class_list":["post-18385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-diagnostics","category-writing-code","tag-code-analysis","tag-cppcorecheck","tag-static-analysis"],"acf":[],"blog_post_summary":"<p>\u70b9\u8fd9\u91cc\u770b\u4e2d\u6587\u7248 We&#8217;re making it easier to configure and use the C++ code analysis features with a set of changes targeting 15.7. In the first 15.7 preview we&#8217;ve cleaned up the UI, fixed our documentation links and, most importantly, simplified the way analysis extensions are configured.\u00a0 If you&#8217;re not familiar with C++ Core Check, it&#8217;s a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/2869"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=18385"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/18385\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=18385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=18385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=18385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}