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
Copy file name to clipboardExpand all lines: docs/build/clang-support-msbuild.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
description: "Learn more about: Clang/LLVM support in Visual Studio projects"
3
3
title: "Clang/LLVM support in Visual Studio projects"
4
-
ms.date: 11/11/2021
4
+
ms.date: 06/29/2022
5
5
ms.description: "Configure a Visual Studio MSBuild project to use the Clang/LLVM toolchain."
6
6
helpviewer_keywords: ["Clang support for C++ MSBuild projects"]
7
7
---
@@ -35,7 +35,7 @@ To configure a Visual Studio project to use Clang, right-click on the project no
35
35
36
36
If you're using the Clang tools that are bundled with Visual Studio, no extra steps are required. For Windows projects, Visual Studio by default invokes Clang in [clang-cl](https://llvm.org/devmtg/2014-04/PDFs/Talks/clang-cl.pdf) mode. It links with the Microsoft implementation of the Standard Library. By default, **clang-cl.exe** is located in *%VCINSTALLDIR%\\Tools\\Llvm\\bin\\* and *%VCINSTALLDIR%\\Tools\\Llvm\\x64\\bin\\*.
37
37
38
-
If you're using a custom Clang installation, you can either modify **Project** > **Properties** > **VC++ Directories** > **Configuration Properties** > **Executable Directories** by adding the custom Clang installation root as the first directory there, or change the value of the `LLVMInstallDir` property. For more information, see [Set a custom LLVM location](#custom_llvm_location).
38
+
If you're using a custom Clang installation, you can change the value of the `LLVMInstallDir` property. For more information, see [Set a custom LLVM location](#custom_llvm_location).
@@ -34,9 +34,9 @@ You can precompile both C and C++ programs. In C++ programming, it's common prac
34
34
35
35
You can precompile any C or C++ code; you're not limited to precompiling only header files.
36
36
37
-
Precompiling requires planning, but it offers significantly faster compilations if you precompile source code other than simple header files.
37
+
Precompiling requires planning, but it offers much faster compilations if you precompile source code other than simple header files.
38
38
39
-
Precompile code when you know that your source files use common sets of header files but don't include them in the same order, or when you want to include source code in your precompilation.
39
+
Precompile code when you know that your source files use common sets of header files, or when you want to include source code in your precompilation.
40
40
41
41
The precompiled-header options are [`/Yc` (Create Precompiled Header File)](reference/yc-create-precompiled-header-file.md) and [`/Yu` (Use Precompiled Header File)](reference/yu-use-precompiled-header-file.md). Use **`/Yc`** to create a precompiled header. When used with the optional [`hdrstop`](../preprocessor/hdrstop.md) pragma, **`/Yc`** lets you precompile both header files and source code. Select **`/Yu`** to use an existing precompiled header in the existing compilation. You can also use **`/Fp`** with the **`/Yc`** and **`/Yu`** options to provide an alternative name for the precompiled header.
42
42
@@ -50,7 +50,7 @@ Because PCH files contain information about the machine environment and memory a
50
50
51
51
The [`/Yu`](reference/yu-use-precompiled-header-file.md) compiler option lets you specify which PCH file to use.
52
52
53
-
When you use a PCH file, the compiler assumes the same compilation environment (one that uses consistent compiler options, pragmas, and so on) that was in effect when you created the PCH file, unless you specify otherwise. If the compiler detects an inconsistency, it issues a warning and identifies the inconsistency where possible. Such warnings don't necessarily indicate a problem with the PCH file; they simply warn you of possible conflicts. Consistency requirements for PCH files are described in the following sections.
53
+
When you use a PCH file, the compiler assumes the same compilation environment that was in effect when you created the PCH file, unless you specify otherwise. The compilation environment includes the compiler options, pragmas, and so on. If the compiler detects an inconsistency, it issues a warning and identifies the inconsistency where possible. Such warnings don't necessarily indicate a problem with the PCH file; they simply warn you of possible conflicts. Consistency requirements for PCH files are described in the following sections.
54
54
55
55
### Compiler option consistency
56
56
@@ -144,7 +144,7 @@ This table lists compiler options that might trigger an inconsistency warning wh
144
144
|**`/D `**| Define constants and macros | Must be the same between the compilation that created the precompiled header and the current compilation. The state of defined constants isn't checked. However, unpredictable results can occur if your files depend on the values of the changed constants. |
145
145
|**`/E`** or **`/EP`**| Copy preprocessor output to standard output | Precompiled headers don't work with the **`/E`** or **`/EP`** option. |
146
146
|**`/Fr`** or **`/FR`**| Generate Microsoft Source Browser information | For the **`/Fr`** and **`/FR`** options to be valid with the **`/Yu`** option, they must also have been in effect when the precompiled header was created. Subsequent compilations that use the precompiled header also generate Source Browser information. Browser information is placed in a single *`.sbr`* file and is referenced by other files in the same manner as CodeView information. You can't override the placement of Source Browser information. |
147
-
|**`/GA`**, **`/GD`**, **`/GE`**, **`/Gw`**, or **`/GW`**| Windows protocol options | Must be the same between the compilation that created the precompiled header and the current compilation. If these options differ, a warning message results. |
147
+
|**`/GA`**, **`/GD`**, **`/GE`**, **`/Gw`**, or **`/GW`**| Windows protocol options | Must be the same between the compilation that created the precompiled header and the current compilation. The compiler emits a warning if these options differ. |
148
148
|**`/Zi`**| Generate complete debugging information | If this option is in effect when the precompiled header is created, subsequent compilations that use the precompilation can use that debugging information. If **`/Zi`** isn't in effect when the precompiled header is created, subsequent compilations that use the precompilation and the **`/Zi`** option trigger a warning. The debugging information is placed in the current object file, and local symbols defined in the precompiled header aren't available to the debugger. |
149
149
150
150
> [!NOTE]
@@ -158,7 +158,7 @@ For another approach to using the manual precompiled-header options in a project
158
158
159
159
## PCH files in the build process
160
160
161
-
The code base of a software project is often contained in multiple C or C++ source files, object files, libraries, and header files. Typically, a makefile coordinates the combination of these elements into an executable file. The following figure shows the structure of a makefile that uses a precompiled header file. The NMAKE macro names and the file names in this diagram are consistent with the ones in the example code found in [Sample makefile for PCH](#sample-makefile-for-pch) and [Example code for PCH](#example-code-for-pch).
161
+
The code base of a software project is often contained in multiple C or C++ source files, object files, libraries, and header files. Typically, a makefile coordinates the combination of these elements into an executable file. The following figure shows the structure of a makefile that uses a precompiled header file. The NMAKE macro names and the file names in this diagram are consistent with the example code found in [Sample makefile for PCH](#sample-makefile-for-pch) and [Example code for PCH](#example-code-for-pch).
162
162
163
163
The figure uses three diagrammatic devices to show the flow of the build process. Named rectangles represent each file or macro; the three macros represent one or more files. Shaded areas represent each compile or link action. Arrows show which files and macros are combined during the compilation or linking process.
164
164
@@ -248,6 +248,8 @@ For more information on makefiles, see [NMAKE reference](reference/nmake-referen
248
248
249
249
The following source files are used in the makefile described in [PCH files in the build process](#pch-files-in-the-build-process) and [Sample makefile for PCH](#sample-makefile-for-pch). The comments contain important information.
250
250
251
+
Source file `ANOTHER.H`:
252
+
251
253
```cpp
252
254
// ANOTHER.H : Contains the interface to code that is not
253
255
// likely to change.
@@ -259,6 +261,8 @@ void savemoretime( void );
259
261
#endif// __ANOTHER_H
260
262
```
261
263
264
+
Source file `STABLE.H`:
265
+
262
266
```cpp
263
267
// STABLE.H : Contains the interface to code that is not likely
264
268
// to change. List code that is likely to change
@@ -271,6 +275,8 @@ void savetime( void );
271
275
#endif// __STABLE_H
272
276
```
273
277
278
+
Source file `UNSTABLE.H`:
279
+
274
280
```cpp
275
281
// UNSTABLE.H : Contains the interface to code that is
276
282
// likely to change. As the code in a header
@@ -285,6 +291,8 @@ void notstable( void );
285
291
#endif// __UNSTABLE_H
286
292
```
287
293
294
+
Source file `APPLIB.CPP`:
295
+
288
296
```cpp
289
297
// APPLIB.CPP : This file contains the code that implements
290
298
// the interface code declared in the header
@@ -310,6 +318,8 @@ void notstable( void )
310
318
}
311
319
```
312
320
321
+
Source file `MYAPP.CPP`:
322
+
313
323
```cpp
314
324
// MYAPP.CPP : Sample application
315
325
// All precompiled code other than the file listed
@@ -68,6 +68,8 @@ All the existing mechanisms to enable, disable, and suppress warnings still work
68
68
69
69
This sample program has two source files, *`program.cpp`* and *`header_file.h`*. The *`header_file.h`* file is in an *`include_dir`* subdirectory of the directory containing the *`program.cpp`* file:
@@ -42,6 +42,8 @@ This declaration isn't available for 64-bit projects.
42
42
43
43
The following code, when compiled with **/Gh**, shows how `_penter` is called twice; once when entering function `main` and once when entering function `x`. The example consists of two source files, which you compile separately.
Specify standards conformance mode to the compiler. Use this option to help you identify and fix conformance issues in your code, to make it both more correct and more portable.
12
12
@@ -41,7 +41,7 @@ The MSVC compiler in earlier versions of Visual Studio 2017 doesn't support all
41
41
42
42
Here are some examples of code that is detected as non-conforming when you use **`/permissive-`**, along with suggested ways to fix the issues.
43
43
44
-
#### Use default as an identifier in native code
44
+
#### Use `default` as an identifier in native code
45
45
46
46
```cpp
47
47
voidfunc(int default); // Error C2321: 'default' is a keyword, and
@@ -103,6 +103,8 @@ union U
103
103
104
104
#### Hidden friend name lookup rules
105
105
106
+
A declaration outside a class can make a hidden friend visible:
107
+
106
108
```cpp
107
109
// Example 1
108
110
structS {
@@ -115,6 +117,8 @@ using type = void (*)(S *);
115
117
type p = &f; // error C2065: 'f': undeclared identifier.
116
118
```
117
119
120
+
Use of literal `nullptr` can prevent argument dependent lookup:
121
+
118
122
```cpp
119
123
// Example 2
120
124
struct S {
@@ -158,19 +162,25 @@ void func() {
158
162
}
159
163
```
160
164
161
-
#### Use of ATL Attributes
165
+
#### Use of ATL attributes
166
+
167
+
Microsoft-specific ATL attributes can cause issues under **`/permissive-`**:
162
168
163
169
```cpp
164
170
// Example 1
165
171
[uuid("594382D9-44B0-461A-8DE3-E06A3E73C5EB")]
166
172
classA {};
167
173
```
168
174
175
+
You can fix the issue by using the **`__declspec`** form instead:
176
+
169
177
```cpp
170
178
// Fix for example 1
171
179
class __declspec(uuid("594382D9-44B0-461A-8DE3-E06A3E73C5EB")) B {};
172
180
```
173
181
182
+
A more complex example:
183
+
174
184
```cpp
175
185
// Example 2
176
186
[emitidl];
@@ -187,6 +197,8 @@ class CFoo : public ICustom
187
197
{};
188
198
```
189
199
200
+
Resolution requires extra build steps. In this case, create an IDL file:
201
+
190
202
```cpp
191
203
// Fix for example 2
192
204
// First, create the *.idl file. The vc140.idl generated file can be
@@ -241,7 +253,7 @@ Common errors that may result from this change include:
241
253
242
254
- `error C2446: ':': no conversion from 'B' to 'A'`
243
255
244
-
A typical code pattern that can cause this issue is when some class `C` provides both a non-explicit constructor from another type `T` and a non-explicit conversion operator to type `T`. In this case, both the conversion of the second argument to the type of the third argument, and the conversion of the third argument to the type of the second argument, are valid conversions. Since both are valid, it's ambiguous according to the standard.
256
+
A typical code pattern that can cause this issue is when some class `C` provides both a non-explicit constructor from another type `T` and a non-explicit conversion operator to type `T`. The conversion of the second argument to the third argument's type is a valid conversion. So is the conversion of the third argument to the second argument's type. Since both are valid, it's ambiguous according to the standard.
245
257
246
258
```cpp
247
259
// Example 1: class that provides conversion to and initialization from some type T
0 commit comments