diff --git a/docs/code-quality/media/cppcorecheck_codeanalysis_extensions.png b/docs/code-quality/media/cppcorecheck_codeanalysis_extensions.png index 4e78e9bf00f..088ee4ac784 100644 Binary files a/docs/code-quality/media/cppcorecheck_codeanalysis_extensions.png and b/docs/code-quality/media/cppcorecheck_codeanalysis_extensions.png differ diff --git a/docs/code-quality/media/cppcorecheck_codeanalysis_general.png b/docs/code-quality/media/cppcorecheck_codeanalysis_general.png index 7eb58065707..916c7e4ddd8 100644 Binary files a/docs/code-quality/media/cppcorecheck_codeanalysis_general.png and b/docs/code-quality/media/cppcorecheck_codeanalysis_general.png differ diff --git a/docs/code-quality/native-minimum-rules-rule-set.md b/docs/code-quality/native-minimum-rules-rule-set.md index 2fc7141f3e2..dc8842a670a 100644 --- a/docs/code-quality/native-minimum-rules-rule-set.md +++ b/docs/code-quality/native-minimum-rules-rule-set.md @@ -75,6 +75,12 @@ The Microsoft Native Minimum Rules focus on the most critical problems in your n |[C6704](../code-quality/c6704.md)|Unexpected Annotation Expression Error| |[C6705](../code-quality/c6705.md)|Expected number of arguments for annotation does not match actual number of arguments for annotation| |[C6706](../code-quality/c6706.md)|Unexpected Annotation Error for annotation| +|[C26450](../code-quality/c26450.md)|RESULT_OF_ARITHMETIC_OPERATION_PROVABLY_LOSSY| +|[C26451](../code-quality/c26451.md)|RESULT_OF_ARITHMETIC_OPERATION_CAST_TO_LARGER_SIZE| +|[C26452](../code-quality/c26452.md)|SHIFT_COUNT_NEGATIVE_OR_TOO_BIG| +|[C26453](../code-quality/c26453.md)|LEFTSHIFT_NEGATIVE_SIGNED_NUMBER| +|[C26454](../code-quality/c26454.md)|RESULT_OF_ARITHMETIC_OPERATION_NEGATIVE_UNSIGNED| +|[C26495](../code-quality/c26495.md)|MEMBER_UNINIT| |[C28021](../code-quality/c28021.md)|The parameter being annotated must be a pointer| |[C28182](../code-quality/c28182.md)|Dereferencing NULL pointer. The pointer contains the same NULL value as another pointer did.| |[C28202](../code-quality/c28202.md)|Illegal reference to non-static member| diff --git a/docs/code-quality/native-recommended-rules-rule-set.md b/docs/code-quality/native-recommended-rules-rule-set.md index b4f6f2362c3..69928317a62 100644 --- a/docs/code-quality/native-recommended-rules-rule-set.md +++ b/docs/code-quality/native-recommended-rules-rule-set.md @@ -142,6 +142,9 @@ The Native Recommended Rules focus on the most critical and common problems in y |[C26116](../code-quality/c26116.md)|Failing to acquire or to hold lock| |[C26117](../code-quality/c26117.md)|Releasing unheld lock| |[C26140](../code-quality/c26140.md)|Concurrency SAL annotation error| +|[C26441](../code-quality/c26441.md)|NO_UNNAMED_GUARDS| +|[C26444](../code-quality/c26444.md)|NO_UNNAMED_RAII_OBJECTS| +|[C26498](../code-quality/c26498.md)|USE_CONSTEXPR_FOR_FUNCTIONCALL| |[C28020](../code-quality/c28020.md)|The expression is not true at this call| |[C28021](../code-quality/c28021.md)|The parameter being annotated must be a pointer| |[C28022](../code-quality/c28022.md)|The function class(es) on this function do not match the function class(es) on the typedef used to define it.| diff --git a/docs/code-quality/using-the-cpp-core-guidelines-checkers.md b/docs/code-quality/using-the-cpp-core-guidelines-checkers.md index 4e21cf0c174..8205e1cfcf4 100644 --- a/docs/code-quality/using-the-cpp-core-guidelines-checkers.md +++ b/docs/code-quality/using-the-cpp-core-guidelines-checkers.md @@ -1,6 +1,6 @@ --- title: Using the C++ Core Guidelines checkers -ms.date: 11/04/2016 +ms.date: 08/14/2018 ms.topic: "conceptual" author: mikeblome ms.author: mblome @@ -19,13 +19,11 @@ The C++ Core Guidelines are a portable set of guidelines, rules, and best practi ## Enable the C++ Core Check guidelines in Code Analysis You can enable code analysis on your project by selecting the **Enable Code Analysis on Build** checkbox in the **Code Analysis** section of the **Property Pages** dialog for your project. - ![Property page for Code Analysis General settings](../code-quality/media/cppcorecheck_codeanalysis_general.png) + ![Property page for Code Analysis General settings](media/cppcorecheck_codeanalysis_general.png) - The C++ Core Check rules are extensions to the default rule sets that run when code analysis is enabled. Because the C++ Core Check rules are under development, some rules are well established, and some may not be ready for use on all code, but may still be informative. The rules are divided into two groups: released and experimental. You can choose whether to run the released or experimental rules in the properties for your project. + A subset of C++ Core Check rules is included in the Microsoft Native Recommended rule set that runs by default when code analysis is enabled. To enable additional Core Check rules, click on the dropdown and choose which rule sets you want to include: - ![Property page for Code Analysis Extensions settings](../code-quality/media/cppcorecheck_codeanalysis_extensions.png) - - To enable or disable the C++ Core Check rule sets, open the **Property Pages** dialog for your project. Under **Configuration Properties**, expand **Code Analysis**, **Extensions**. In the dropdown control next to **Enable C++ Core Check (Released)** or **Enable C++ Core Check (Experimental)**, choose **Yes** or **No**. Choose **OK** or **Apply** to save your changes. + ![Dropdown for additional C++ Core Check rule sets](media/cppcorecheck_codeanalysis_extensions.png) ## Examples Here's an example of some of the issues that the C++ Core Check rules can find: @@ -161,14 +159,14 @@ These macros correspond to the rule sets and expand into a space-separated list ## Enabling the C++ Core Guidelines Checker on specific project files Sometimes it may be useful to do focused code analysis and still use the Visual Studio IDE. The following sample scenario can be used for large projects to save build time and to make it easier to filter results: -1. In the command shell set the `esp.extension` and `esp.annotationbuildlevel` environment variables. -2. To inherit these variables, start Visual Studio from the command shell. -3. Load your project and open its properties. -4. Enable code analysis, pick the appropriate rule sets, but do not enable code analysis extensions. -5. Go to the file you want to analyze with the C++ Core Guidelines Checker and open its properties. -6. Choose **C/C++\Command Line Options** and add `/analyze:plugin EspXEngine.dll` -7. Disable the use of precompiled header (**C/C++\Precompiled Headers**). This is necessary because the extensions engine may attempt to read its internal information from the precompiled header (PCH); if the PCH compiled with default project options, it will not be compatible. -8. Rebuild the project. The common PREFast checks should run on all files. Because the C++ Core Guidelines Checker is not enabled by default, it should only run on the file that is configured to use it. +1. In the command shell set the `esp.extension` and `esp.annotationbuildlevel` environment variables. +2. To inherit these variables, start Visual Studio from the command shell. +3. Load your project and open its properties. +4. Enable code analysis, pick the appropriate rule sets, but do not enable code analysis extensions. +5. Go to the file you want to analyze with the C++ Core Guidelines Checker and open its properties. +6. Choose **C/C++\Command Line Options** and add `/analyze:plugin EspXEngine.dll` +7. Disable the use of precompiled header (**C/C++\Precompiled Headers**). This is necessary because the extensions engine may attempt to read its internal information from the precompiled header (PCH); if the PCH compiled with default project options, it will not be compatible. +8. Rebuild the project. The common PREFast checks should run on all files. Because the C++ Core Guidelines Checker is not enabled by default, it should only run on the file that is configured to use it. ## How to use the C++ Core Guidelines Checker outside of Visual Studio You can use the C++ Core Guidelines checks in automated builds. @@ -211,12 +209,12 @@ If you use a build system that doesn’t rely on MSBuild you can still run the c You have to set a few environment variables and use proper command-line options for the compiler. It is better to work under the "Native Tools Command Prompt" environment so that you don’t have to search for specific paths for the compiler, include directories, etc. -1. **Environment variables** +1. **Environment variables** - `set esp.extensions=cppcorecheck.dll` This tells the engine to load the C++ Core Guidelines module. - `set esp.annotationbuildlevel=ignore` This disables the logic that processes SAL annotations. Annotations don’t affect code analysis in the C++ Core Guidelines Checker, yet their processing takes time (sometimes a long time). This setting is optional, but highly recommended. - `set caexcludepath=%include%` We highly recommend that you disable warnings which fire on standard headers. You can add more paths here, for example the path to the common headers in your project. -2. **Command line options** - - `/analyze` Enables code analysis (consider also using /analyze:only and /analyze:quiet). +2. **Command line options** + - `/analyze` Enables code analysis (consider also using /analyze:only and /analyze:quiet). - `/analyze:plugin EspXEngine.dll` This option loads the Code Analysis Extensions engine into the PREfast. This engine, in turn, loads the C++ Core Guidelines Checker.