Skip to content

Commit 5b294c8

Browse files
authored
Merge pull request #5576 from MicrosoftDocs/main
5/24/2024 AM Publish
2 parents bb2c406 + e448259 commit 5b294c8

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

docs/code-quality/clang-tidy.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Using Clang-Tidy in Visual Studio
33
description: "How to use Clang-Tidy in Visual Studio for Microsoft C++ code analysis."
44
ms.date: 03/1/2022
55
ms.topic: "conceptual"
6-
f1_keywords: ["vs.codeanalysis.clangtidy"]
6+
f1_keywords: ["vs.codeanalysis.clangtidy","vs.codeanalysis.propertypages.ClangTidyToolPath"]
77
---
88
# Using Clang-Tidy in Visual Studio
99

@@ -90,6 +90,10 @@ Clang-Tidy runs result in warnings displayed in the Error List, and as in-editor
9090

9191
By default, Clang-Tidy does not set any checks when enabled. To see the list of checks in the command-line version, run `clang-tidy -list-checks` in a developer command prompt. You can configure the checks that Clang-Tidy runs inside Visual Studio. In the project Property Pages dialog, open the **Configuration Properties** > **Code Analysis** > **Clang-Tidy** page. Enter checks to run in the **Clang-Tidy Checks** property. A good default set is `clang-analyzer-*`. This property value 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/).
9292

93+
## Clang-Tidy Tool Directory
94+
95+
If you'd like to have custom rules built into your clang-tidy executable and run it in Microsoft Visual Studio, you can change the path to the executable that Visual Studio runs. In the project Property Pages dialog, open the **Configuration Properties** > **Code Analysis** > **Clang-Tidy** page. Manually type in the path or **Browse** and select the path under the **Clang-Tidy Tool Directory** property. The new executable is used once the change is saved, and the app is recompiled.
96+
9397
## See also
9498

9599
[Clang/LLVM support for MSBuild projects](https://devblogs.microsoft.com/cppblog/clang-llvm-support-for-msbuild-projects/)\
Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,84 @@
11
---
22
description: "Learn more about: Compiler Warning (level 2) C4150"
3-
title: "Compiler Warning (level 2) C4150"
3+
title: Compiler warning (level 2) C4150
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4150"]
66
helpviewer_keywords: ["C4150"]
7-
ms.assetid: ff1760ec-0d9f-4d45-b797-94261624becf
87
---
98
# Compiler Warning (level 2) C4150
109

11-
deletion of pointer to incomplete type 'type'; no destructor called
10+
> deletion of pointer to incomplete type 'type'; no destructor called
1211
13-
The **`delete`** operator is called to delete a type that was declared but not defined, so the compiler cannot find a destructor.
12+
The `delete` operator is called to delete a type that was declared but not defined. The compiler can't find the destructor to call because the definition isn't in the same translation unit as the `delete`.
1413

15-
The following sample generates C4150:
14+
## Example
15+
16+
The following sample generates C4150 by declaring but not defining `class IncClass`:
1617

1718
```cpp
18-
// C4150.cpp
1919
// compile with: /W2
20-
class IncClass;
20+
class IncClass;
21+
22+
void NoDestruct( IncClass* pIncClass )
23+
{
24+
delete pIncClass; // C4150
25+
}
26+
```
27+
28+
To fix the issue, put the definition of `IncClass` in the same file as the `delete`. If the class is declared in a header file, it can be added to the file using `#include`. If the class isn't declared in a header file, the `NoDestruct` function definition may need to be moved into the same file as the `IncClass` definition.
29+
30+
```cpp
31+
// compile with: /W2
32+
#include "IncClass.h"
2133
2234
void NoDestruct( IncClass* pIncClass )
2335
{
2436
delete pIncClass;
25-
} // C4150, define class to resolve
37+
}
38+
```
39+
40+
C4150 will be emitted when the class is defined after the destructor call in the same file. In the following example `IncClass` is declared before being used, but defined after the `delete`:
41+
42+
```cpp
43+
// C4150.cpp
44+
// compile with: /W2
45+
class IncClass;
2646

27-
int main()
47+
void NoDestruct( IncClass* pIncClass )
2848
{
49+
delete pIncClass; // C4150
2950
}
51+
52+
class IncClass
53+
{
54+
public:
55+
IncClass() = default;
56+
~IncClass() = default;
57+
};
3058
```
59+
In this scenario, the use of `delete` needs to be after the class definition.
60+
```cpp
61+
// C4150.cpp
62+
// compile with: /W2
63+
class IncClass;
64+
65+
void NoDestruct( IncClass* pIncClass );
66+
67+
class IncClass
68+
{
69+
public:
70+
IncClass() = default;
71+
~IncClass() = default;
72+
};
73+
74+
void NoDestruct( IncClass* pIncClass )
75+
{
76+
delete pIncClass;
77+
}
78+
79+
```
80+
81+
## See also
82+
83+
* [Projects and build systems](../../build/projects-and-build-systems-cpp.md)
84+
* [Source files and source programs](../../c-language/source-files-and-source-programs.md)

0 commit comments

Comments
 (0)