You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5a778ba
Browse filesBrowse the repository at this point in the historyBrowse files
Colin Robertson
authored
Merge pull request MicrosoftDocs#1927 from MicrosoftDocs/master637178218425311584
When the **/Zc:rvalueCast** option is specified, the compiler correctly identifies an rvalue reference type as the result of a cast operation in accordance with the C++11 standard. When the option is not specified, the compiler behavior is the same as in Visual Studio 2012.
10
+
When the **`/Zc:rvalueCast`** option is specified, the compiler correctly identifies an rvalue reference type as the result of a cast operation. Its behavior conforms to the C++11 standard. When the option is unspecified, the compiler behavior is the same as in Visual Studio 2012.
11
11
12
12
## Syntax
13
13
14
-
> **/Zc:rvalueCast**[**-**]
14
+
> **`/Zc:rvalueCast`**\
15
+
> **`/Zc:rvalueCast-`**
15
16
16
17
## Remarks
17
18
18
-
If **/Zc:rvalueCast** is specified, the compiler follows section 5.4 of the C++11 standard and treats only cast expressions that result in non-reference types and cast expressions that result in rvalue references to non-function types as rvalue types. By default, or if **/Zc:rvalueCast-** is specified, the compiler is non-conformant and treats all cast expressions that result in rvalue references as rvalues. For conformance and to eliminate errors in the use of casts, we recommend that you use **/Zc:rvalueCast**.
19
+
If **`/Zc:rvalueCast`** is specified, the compiler follows section 5.4 of the C++11 standard and treats only cast expressions that result in non-reference types and cast expressions that result in rvalue references to non-function types as rvalue types. By default, or if **`/Zc:rvalueCast-`** is specified, the compiler is non-conforming, and treats all cast expressions that result in rvalue references as rvalues. For conformance, and to eliminate errors in the use of casts, we recommend that you use **`/Zc:rvalueCast`**.
19
20
20
-
By default, **/Zc:rvalueCast** is off (**/Zc:rvalueCast-**). The [/permissive-](permissive-standards-conformance.md) compiler option implicitly sets this option, but it can be overridden by using **/Zc:rvalueCast-**.
21
+
By default, **`/Zc:rvalueCast`** is off (**`/Zc:rvalueCast-`**). The [/permissive-](permissive-standards-conformance.md) compiler option implicitly sets this option, but it can be overridden by using **`/Zc:rvalueCast-`**.
21
22
22
-
Use **/Zc:rvalueCast** if you pass a cast expression as an argument to a function that takes an rvalue reference type. The default behavior causes compiler error [C2664](../../error-messages/compiler-errors-2/compiler-error-c2664.md) when the compiler incorrectly determines the type of the cast expression. This example shows a compiler error in correct code when **/Zc:rvalueCast**is not specified:
23
+
Use **`/Zc:rvalueCast`** if you pass a cast expression as an argument to a function that takes an rvalue reference type. The default behavior causes compiler error [C2664](../../error-messages/compiler-errors-2/compiler-error-c2664.md) when the compiler incorrectly determines the type of the cast expression. This example shows a compiler error in correct code when **`/Zc:rvalueCast`**isn't specified:
23
24
24
25
```cpp
25
26
// Test of /Zc:rvalueCast
@@ -57,7 +58,7 @@ struct Test1 {
57
58
};
58
59
```
59
60
60
-
The default compiler behavior may not report error C2102 when appropriate. In this example, the compiler does not report an error if the address of an rvalue created by an identity cast is taken when **/Zc:rvalueCast** is not specified:
61
+
The default compiler behavior may not report error C2102 when appropriate. In this example, the compiler doesn't report an error if the address of an rvalue created by an identity cast is taken when **`/Zc:rvalueCast`** is unspecified:
61
62
62
63
```cpp
63
64
int main() {
@@ -74,10 +75,10 @@ For more information about conformance issues in Visual C++, see [Nonstandard Be
74
75
75
76
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
description: "How to use Clang-Tidy in Visual Studio for Microsoft C++ code analysis."
4
+
ms.date: 02/19/2020
4
5
ms.topic: "conceptual"
5
6
f1_keywords:
6
7
- "vs.codeanalysis.clangtidy"
@@ -9,17 +10,25 @@ ms.author: efessler
9
10
---
10
11
# Using Clang-Tidy in Visual Studio
11
12
12
-
Code Analysis natively supports [Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/) for both MSBuild and CMake projects, whether using Clang or MSVC toolsets. Clang-Tidy checks can run as part of background code analysis, appear as in-editor warnings (squiggles), and display in the Error List.
13
+
::: moniker range="<=vs-2017"
13
14
14
-
In order to use Clang-Tidy, the "C++ Clang tools for Windows" component must be installed via the Visual Studio Installer.
15
+
Support for Clang-Tidy requires Visual Studio 2019 version 16.4 or later. To see the documentation, choose Visual Studio 2019 in the documentation version selector.
15
16
16
-
Clang-Tidy is the default analysis tool when using the LLVM/clang-cl toolset, available in both MSBuild and CMake. You can configure it to run alongside or replace the standard Code Analysis experience when using an MSVC toolset; if using the clang-cl toolset Microsoft Code Analysis will not be available.
17
+
::: moniker-end
17
18
18
-
Clang-Tidy runs after successful compilation; you may need to resolve source code errors to get Clang-Tidy results.
19
+
::: moniker range=">=vs-2019"
20
+
21
+
Code Analysis natively supports [Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/) for both MSBuild and CMake projects, whether using Clang or MSVC toolsets. Clang-Tidy checks can run as part of background code analysis. They appear as in-editor warnings (squiggles), and display in the Error List.
22
+
23
+
Clang-Tidy support is available starting in Visual Studio 2019 version 16.4. It's included automatically when you choose a C++ workload in the Visual Studio Installer.
24
+
25
+
Clang-Tidy is the default analysis tool when using the LLVM/clang-cl toolset, available in both MSBuild and CMake. You can configure it when using an MSVC toolset to run alongside, or to replace, the standard Code Analysis experience. If you use the clang-cl toolset, Microsoft Code Analysis is unavailable.
26
+
27
+
Clang-Tidy runs after successful compilation. You may need to resolve source code errors to get Clang-Tidy results.
19
28
20
29
## MSBuild
21
30
22
-
You can configure Clang-Tidy to run as part of both Code Analysis and build under the **Code Analysis** > **General** page in the Project Properties window. Options to configure the tool can be found under the Clang-Tidy sub-menu.
31
+
You can configure Clang-Tidy to run as part of both Code Analysis and build under the **Code Analysis** > **General** page in the Project Properties window. Options to configure the tool can be found under the Clang-Tidy submenu.
23
32
24
33
For more information, see [How to: Set Code Analysis Properties for C/C++ Projects](../code-quality/how-to-set-code-analysis-properties-for-c-cpp-projects.md).
25
34
@@ -29,19 +38,21 @@ In CMake projects, you can configure Clang-Tidy checks within `CMakeSettings.jso
29
38
30
39
-`enableMicrosoftCodeAnalysis`: Enables Microsoft Code Analysis
-`clangTidyChecks`: Clang-Tidy configuration, specified as a comma-separated list, i.e. checks to be enabled or disabled
41
+
-`clangTidyChecks`: Clang-Tidy configuration, specified as a comma-separated list, that is, checks to be enabled or disabled
33
42
34
43
If neither of the "enable" options are specified, Visual Studio will select the analysis tool matching the Platform Toolset used.
35
44
36
45
## Warning display
37
46
38
-
Clang-Tidy runs result in warnings displayed in the Error List and as in-editor squiggles underneath relevant sections of code. Use the "Category" column in the Error List to sort and organize Clang-Tidy warnings. You can configure in-editor warnings by toggling the "Disable Code Analysis Squiggles" setting under **Tools** > **Options**.
47
+
Clang-Tidy runs result in warnings displayed in the Error List, and as in-editor squiggles underneath relevant sections of code. Use the "Category" column in the Error List to sort and organize Clang-Tidy warnings. You can configure in-editor warnings by toggling the "Disable Code Analysis Squiggles" setting under **Tools** > **Options**.
39
48
40
49
## Clang-Tidy configuration
41
50
42
-
You can configure the checks that clang-tidy runs inside Visual Studio via the **Clang-Tidy Checks** option. This input is provided to the **--checks** argument of the tool. Any further configuration can be included in custom **.clang-tidy** files. See the [Clang-Tidy documentation on LLVM.org](https://clang.llvm.org/extra/clang-tidy/) for more details.
51
+
You can configure the checks that clang-tidy runs inside Visual Studio via the **Clang-Tidy Checks** option. This input is provided to the **--checks** argument of the tool. Any further configuration can be included in custom *`.clang-tidy`* files. For more information, see the [Clang-Tidy documentation on LLVM.org](https://clang.llvm.org/extra/clang-tidy/).
43
52
44
53
## See also
45
54
46
55
-[Clang/LLVM Support for MSBuild Projects](https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/)
47
56
-[Clang/LLVM Support for CMake Projects](https://devblogs.microsoft.com/cppblog/visual-studio-cmake-support-clang-llvm-cmake-3-14-vcpkg-and-performance-improvements/)
0 commit comments