Skip to content

Commit 74587c4

Browse files
TylerMSFTTylerMSFT
authored andcommitted
best practice
1 parent beca755 commit 74587c4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/ide/include-cleanup-overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ int main()
109109

110110
The tool doesn't update the comments, but you can see that the code is now using `std::string` and `std::cout` directly. This code is no longer brittle because it doesn't depend on `myHeader.h` to include the other required headers.
111111

112-
## Using include cleanup with large codebases
112+
## Best practice
113113

114-
The recommended approach is to clean up the #includes by first adding direct headers where indirect headers are used. After you have done that for all indirect headers in the file, then remove any unused includes.
114+
Don't remove what appear to be unused header files without first adding indirectly included header files. That's because you may be relying on indirect includes that you (and the tool) aren't aware of in a header file that is otherwise unused. The tool can't tell if you're relying on indirect includes, so add transitively used headers first. Then when you remove unused headers, you won't have code that doesn't compile due to a missing header that was included indirectly by a header file you've removed.
115115

116-
To do this, set the include cleanup setting for **Add missing includes suggestion level** to **Suggestion** (**Tools** > **Options** > **Text Editor** > **C/C++** > **Code Cleanup**). Also set **Remove unused includes suggestion level** to **Suggestion**.
116+
To do this, set the include cleanup setting for **Add missing includes suggestion level** to **Suggestion** (**Tools** > **Options** > **Text Editor** > **C/C++** > **Code Cleanup**). Also set **Remove unused includes suggestion level** to **Suggestion**. Then:
117117

118118
1. In the error list, make sure the filter is set to **Build + IntelliSense**.
119119
1. Look for instances of "Content from #include x is used in this file and transitively included".

0 commit comments

Comments
 (0)