{"id":24779,"date":"2019-08-13T18:17:03","date_gmt":"2019-08-13T18:17:03","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=24779"},"modified":"2019-08-15T22:43:10","modified_gmt":"2019-08-15T22:43:10","slug":"new-c-core-check-rules","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/new-c-core-check-rules\/","title":{"rendered":"New C++ Core Check Rules"},"content":{"rendered":"<p>The C++ Core Guidelines Checker receives three new rules with the release of <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio version 16.3 Preview 2<\/a>. In addition, some warnings published in the warnings.h that ships with Visual Studio have been moved or renamed.<\/p>\n<p>Below is a quick summary of these additions. For more detailed information, please see the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/code-analysis-for-cpp-corecheck\">C++ Core Guidelines Checker Reference<\/a> documentation.<\/p>\n<p>If you\u2019re just getting started with native code analysis tools, take a look at our introductory <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/quick-start-code-analysis-for-c-cpp\">quick start for Code Analysis for C\/C++<\/a>.<\/p>\n<h2 id=\"new-rule-set\">New rule set<\/h2>\n<p>The &#8220;Enum Rules&#8221; set has been added in this release. It can be enabled by selecting &#8220;C++ Core Check Enum Rules&#8221; in the Project Settings dialog. This rule set can be used to detect common errors when using enums as specified in the <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#S-enum\">Core Guidelines Enum section<\/a>.<\/p>\n<h2 id=\"new-rules\">New rules<\/h2>\n<h3 id=\"addition-to-const-rules\">Const rules<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26814\">C26814<\/a> &#8211; &#8220;USE_CONSTEXPR_RATHER_THAN_CONST&#8221;<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">C26814 is a more aggressive implementation of <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#con5-use-constexpr-for-values-that-can-be-computed-at-compile-time\">Con.5<\/a>. Our previous warning, C26498 (&#8220;USE_CONSTEXPR_FOR_FUNCTIONCALL&#8221;), checks for constexpr conversion candidates by evaluating all const variables whose values are derived from constexpr functions. This new rule evaluates all const variables to determine whether their values can be determined at compile time.NOTE: This rule is <em>not<\/em> included in the &#8220;Microsoft Native Recommended Rules&#8221; rule set by default and will need to be added or run via the &#8220;C++ Core Check Const Rules&#8221; rule set.<\/p>\n<h3 id=\"addition-to-enum-rules\">Enum rules<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26812\">C26812<\/a> &#8211; &#8220;USE_ENUM_CLASS_INSTEAD_OF_ENUM&#8221;<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">C26812 implements <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#enum3-prefer-class-enums-over-plain-enums\">Enum.3<\/a>. It recommends declaring all enums as a scoped enums; that is, declaring &#8220;enum&#8221; as &#8220;enum class&#8221;. This is largely to prevent unintended errors when using enums as they are too readily converted to int.<\/p>\n<h3 id=\"addition-to-type-rules\">Type rules<\/h3>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26478\">C26478<\/a> &#8211; &#8220;NO_MOVE_OP_ON_CONST&#8221;<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">C26478 is designed to prevent unnecessary calls to &#8220;std::move&#8221;. Specifically, this rule hopes to curb the usage of &#8220;std::move&#8221; on constant objects. When calling &#8220;std::move&#8221; on a const object, the move operation performs a copy rather than moving the ownership of the object, which is likely not what the developer intended. For further reading, refer to <a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/blob\/master\/CppCoreGuidelines.md#es56-write-stdmove-only-when-you-need-to-explicitly-move-an-object-to-another-scope\">ES.56<\/a>.<\/p>\n<h2 id=\"warningsh-changes\">Warnings.h changes<\/h2>\n<ul>\n<li>The warning <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26477\">C26477<\/a> &#8220;USE_NULLPTR&#8221; was renamed to &#8220;USE_NULLPTR_NOT_CONSTANT&#8221;.<\/li>\n<li>The rule category &#8220;CPPCORECHECK_EXPERIMENTAL_WARNINGS&#8221; was removed from this release. The warning it contained, <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26800\">C26800<\/a> (&#8220;USE_OF_A_MOVED_FROM_OBJECT&#8221;), was added to the &#8220;CPPCORECHECK_LIFETIME_WARNINGS&#8221; rules.<\/li>\n<li>The warnings <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26810\">C26810<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/code-quality\/c26811\">C26811<\/a>, (&#8220;COROUTINES_USE_AFTER_FREE_CAPTURE&#8221; and &#8220;COROUTINES_USE_AFTER_FREE_PARAM&#8221; respectively, were removed from the &#8220;CPPCORECHECK_CONCURRENCY_WARNINGS&#8221; category and added to &#8220;CPPCORECHECK_LIFETIME_WARNINGS&#8221;.<\/li>\n<\/ul>\n<h2 id=\"feedback\">Feedback<\/h2>\n<p>We would appreciate it if you tried these new rules out and gave us feedback on them. We can be reached via the comments below, via email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>), or on Twitter <a href=\"https:\/\/twitter.com\/VisualC\">@VisualC<\/a>. If you encounter any problems, please report them via the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2019\">Report A Problem<\/a> tool in Visual Studio or on the <a href=\"https:\/\/developercommunity.visualstudio.com\/content\/problem\/post.html\">Visual Studio Developer Community<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The C++ Core Guidelines Checker receives three new rules with the release of Visual Studio version 16.3 Preview 2. In addition, some warnings published in the warnings.h that ships with Visual Studio have been moved or renamed. Below is a quick summary of these additions. For more detailed information, please see the C++ Core Guidelines [&hellip;]<\/p>\n","protected":false},"author":6068,"featured_media":24850,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-24779","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>The C++ Core Guidelines Checker receives three new rules with the release of Visual Studio version 16.3 Preview 2. In addition, some warnings published in the warnings.h that ships with Visual Studio have been moved or renamed. Below is a quick summary of these additions. For more detailed information, please see the C++ Core Guidelines [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24779","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\/6068"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=24779"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/24779\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/24850"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=24779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=24779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=24779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}