Skip to content

Commit 1bad6b6

Browse files
learn-build-service-prod[bot]TylerMSFTprmerger-automator[bot]TylerMSFTPhilKang0704
authored
Repo sync for protected branch (#4958)
* add link to backend improvements * change feedback system from github issues to the new UUF system (#5208) Co-authored-by: TylerMSFT <[email protected]> * new article: include diagnostics * acrolinx and edit * acrolinx * small edits * clarified specific to C++ * clarify that this is C++ include diagnostics * fix github #4953 --------- Co-authored-by: TylerMSFT <[email protected]> Co-authored-by: prmerger-automator[bot] <40007230+prmerger-automator[bot]@users.noreply.github.com> Co-authored-by: Tyler Whitney <[email protected]> Co-authored-by: Phil <[email protected]> Co-authored-by: James Barnett <[email protected]> Co-authored-by: Learn Build Service GitHub App <Learn Build Service [email protected]>
1 parent da8d09e commit 1bad6b6

8 files changed

+114
-4
lines changed

docs/docfx.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"searchScope": [
5757
"C++"
5858
],
59-
"feedback_system": "GitHub",
59+
"feedback_system": "Standard",
6060
"feedback_github_repo": "MicrosoftDocs/cpp-docs",
6161
"feedback_product_url": "https://developercommunity.visualstudio.com/cpp/",
6262
"feedback_help_link_url": "https://learn.microsoft.com/en-us/answers/tags/314/cpp",

docs/ide/include-diagnostics.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: "C++ Include Diagnostics"
3+
description: "Learn how to use #include Diagnostics in Visual Studio to analyze how often something from an include file is used and how an #include impacts build time."
4+
ms.date: 10/10/2023
5+
ms.topic: "how-to"
6+
f1_keywords: ["include diagnostics"]
7+
helpviewer_keywords: ["include diagnostics"]
8+
---
9+
# C++ Include Diagnostics in Visual Studio
10+
11+
Starting with Visual Studio 17.8, Visual Studio helps you analyze your C++ `#include` files:
12+
13+
- Displays how often, and where, something from each header file is used.
14+
- Displays the build time for each `#include` file--which helps you identify opportunities to optimize your build time.
15+
16+
## Enable C++ Include Diagnostics and CodeLens
17+
18+
The C++ Include Diagnostics feature is off by default. To turn it on, right-click in the code editor to bring up the context menu, and choose **Include Directives** > **Turn #include Diagnostics On**.
19+
20+
:::image type="complex" source="media/vs2022-enable-include-diagnostics.png" alt-text="A screenshot of the context menu that appears when you right-click in the code editor area.":::
21+
The context menu shows the include directives option highlighted, which reveals two options: Sort # include directives and turn # include diagnostics on.
22+
:::image-end:::
23+
24+
Information about your `#include` files is displayed via CodeLens, which is off by default. To turn on the relevant CodeLens settings, navigate to **Tools** > **Options** > **Text Editor** > **All Languages** > **CodeLens** and confirm both **Show C++ #include references** and **Show C++ compilation times** are enabled.
25+
26+
:::image type="complex" source="media/vs2022-enable-code-lens-for-includes.png" alt-text="A screenshot of the options window.":::
27+
The options window is set to Text Editor > All Languages > CodeLens. The Show C++ # include references and Show C++ compilation times options are highlighted.
28+
:::image-end:::
29+
30+
## View `#include` references
31+
32+
To try out Include Diagnostics, create a new C++ console project. Replace the contents of the main `.cpp` file with the following code:
33+
34+
```cpp
35+
#include <iostream>
36+
#include <vector>
37+
38+
// a function that takes a vector of integers and prints them out
39+
void print(std::vector<int> &vec)
40+
{
41+
for (int i : vec)
42+
{
43+
std::cout << i << std::endl;
44+
}
45+
std::cout << std::endl;
46+
}
47+
48+
// a function that takes a vector of integers and adds 10 to each element of the vector and store the result in a new vector
49+
std::vector<int> add10(std::vector<int>& vec)
50+
{
51+
std::vector<int> newVec;
52+
for (int i : vec)
53+
{
54+
newVec.push_back(i + 10);
55+
}
56+
return newVec;
57+
}
58+
59+
int main()
60+
{
61+
std::vector<int> vec = { 7, 5, 16, 8 };
62+
63+
print(vec);
64+
auto newVec = add10(vec);
65+
print(newVec);
66+
}
67+
```
68+
69+
When C++ Include Diagnostics are turned on, the number of times code from a header file is referenced in the current code file is displayed above the header file. It looks like this for the previous code sample:
70+
71+
```cpp
72+
6 references
73+
#include <iostream>
74+
5 references
75+
#include <vector>
76+
```
77+
78+
In the code editor, select **5 references** above `#include <vector>` and a summary of locations where code from `<vector>` is used in this file is displayed:
79+
80+
:::image type="complex" source="media/visual-studio-2022-codelens-include-references.png" alt-text="A screenshot of the C++ Include Diagnostics context window showing where code from the vector header file is used.":::
81+
The C++ Include Diagnostics context window shows that there are five places in the code where code from the vector header file is used in the current code file. For example, it's used twice on the definition of the add10 function, as a return value and parameter. It's used on line 17 in the declaration of newVec, and so on.
82+
:::image-end:::
83+
84+
Select an item to go to its location in your code.
85+
86+
## View `#include` build time
87+
88+
To see the build time for each file you `#include`, first build using Build Insights.
89+
90+
Turn on Build Insights from the main menu bar by selecting **Build** > **Run Build Insights on Solution** > **Build**. After the build completes, a window appears to list the build times for the various files that are compiled. Return to the source code window, and the build time for each `#include` file is displayed in CodeLens. It looks similar to this:
91+
92+
```cpp
93+
6 references | Build: 0.3560s
94+
#include <iostream>
95+
5 references | Build 0.0360s
96+
#include <vector>
97+
```
98+
99+
If you have an `#include` directive that is used infrequently, but significantly impacts your compile time, this tool can help you identify it.
100+
101+
In this article, you've seen how to turn on C++ Include Diagnostics and CodeLens, and how to use C++ Include Diagnostics to analyze how often something from an include file is used and how an `#include` impacts build time.
102+
103+
## See also
104+
105+
[C/C++ Include Cleanup overview](include-cleanup-overview.md)\
106+
[Include Cleanup messages](include-cleanup-messages.md)
Loading
Loading
Loading

docs/ide/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ items:
1616
href: ../ide/include-cleanup-config.md
1717
- name: Include Cleanup messages
1818
href: ../ide/include-cleanup-messages.md
19+
- name: C++ Include Diagnostics
20+
href: include-diagnostics.md
1921
- name: Set your C++ coding preferences
2022
href: ../ide/how-to-set-preferences.md
2123
- name: Collaborate using Live Share for C++

docs/overview/visual-cpp-language-conformance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ For details on conformance improvements, see [C++ conformance improvements in Vi
116116
| &emsp;[`P1099R5 Using enum`](https://wg21.link/P1099R5) | VS 2019 16.4 <sup>[20](#note_20)</sup> |
117117
| &emsp;[`P1186R3 When do you actually use <=>`](https://wg21.link/P1186R3) | VS 2019 16.4 <sup>[20](#note_20)</sup> |
118118
| &emsp;[`P1630R1 Spaceship needs a tune-up`](https://wg21.link/P1630R1) | VS 2019 16.4 <sup>[20](#note_20)</sup> |
119-
| &emsp;[`P0306R4 Adding __VA_OPT__ for comma omission and comma deletion`](https://wg21.link/P0306R4) | VS 2019 16.5 <sup>[20](#note_20)</sup> |
119+
| &emsp;[`P0306R4 Adding __VA_OPT__ for comma omission and comma deletion`](https://wg21.link/P0306R4) | VS 2019 16.5. To provide better backward compatibility, `__VA_OPT__` is enabled under `/Zc:preprocessor` across all language versions. |
120120
| &emsp;[`P0614R1 Range-based for-loops with initializers`](https://wg21.link/P0614R1) | VS 2019 16.5 <sup>[20](#note_20)</sup> |
121121
| &emsp;[`P0683R1 Default member initializers for bit-fields`](https://wg21.link/P0683R1) | VS 2019 16.5 <sup>[20](#note_20)</sup> |
122122
| &emsp;[`P1002R1 try-catch blocks in constexpr functions`](https://wg21.link/P1002R1) | VS 2019 16.5 <sup>[20](#note_20)</sup> |

docs/overview/what-s-new-for-visual-cpp-in-visual-studio.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "What's new for C++ in Visual Studio"
33
description: "The new features and fixes in the Microsoft C/C++ compiler and tools in Visual Studio."
4-
ms.date: 02/07/2024
4+
ms.date: 02/21/2024
55
ms.service: "visual-cpp"
66
ms.subservice: "ide"
77
ms.custom: intro-whats-new
@@ -37,7 +37,9 @@ Briefly, some of the new features are:
3737
`<mdspan>` per [P0009R18](https://wg21.link/P0009R18) and subsequent wording changes that were applied to the C++23 Standard.
3838
Also, `format()` can format pointers per [P2510R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2510r3.pdf).
3939

40-
For a comprehensive summary of new C++ features in Visual Studio 17.9, see [What’s New for C++ Developers in Visual Studio 2022 17.9](https://devblogs.microsoft.com/cppblog/whats-new-for-cpp-developers-in-visual-studio-2022-17-9/).
40+
For a comprehensive summary of new C++ features in Visual Studio 17.9, see [MSVC Backend Updates since Visual Studio 2022 version 17.3](https://devblogs.microsoft.com/cppblog/msvc-backend-updates-since-visual-studio-2022-version-17-3/).
41+
42+
For a summary of C++ compiler backend improvements since Visual Studio 17.3 until now, see [What's new in the Visual C++ compiler backend](https://devblogs.microsoft.com/cppblog/whats-new-in-the-visual-cpp-compiler-backend/).
4143

4244
For a summary of new features in the Visual Studio 17.9 IDE, see [Visual Studio 2022 version 17.9 Release Notes](/visualstudio/releases/2022/release-notes).
4345

0 commit comments

Comments
 (0)