Skip to content

Commit 8bbbb75

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs-pr (branch live)
2 parents e687ce8 + 4dde791 commit 8bbbb75

17 files changed

+115
-2
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
title: "Visual Studio IDE tools for upgrading C++ code"
3+
description: "The C++ code editor and code analysis tools in Visual Studio help you to modernize your C++ code base."
4+
ms.date: "11/13/2019"
5+
ms.topic: "conceptual"
6+
---
7+
# Visual Studio IDE tools for upgrading C++ code
8+
9+
Visual Studio helps you upgrade legacy C++ code with compiler options, code analysis warnings, and editor features such as Quick Fixes, Quick Info, and the enhanced scroll bar. The term "legacy code" refers to any of these categories:
10+
11+
- Code that was formerly allowed by the Microsoft C++ compiler (MSVC) but never conformed to the C++ standard.
12+
13+
To upgrade older non-conformant MSVC code, turn on the [/permissive-](../build/reference/permissive-standards-conformance.md) compiler option. All instances of non-conformant usages are underlined with red squiggles in the code editor. The error messages in the **Error List** window include a recommendation for how to fix the error. Click on the error code to go to its help page in the documentation. If fixing all the errors at once is impractical, you can upgrade non-conformant code in stages by turning on the **permissive-** option, fixing some errors, then turning the option off again. The code will compile with the new improvements, and you can go back and fix the remaining issues at a later time. See the [/permissive-](../build/reference/permissive-standards-conformance.md) page for examples of non-conformant MSVC code.
14+
15+
- Code that was permitted in an earlier version of the C++ standard but has been deprecated or removed in a later version.
16+
17+
To upgrade to a newer language standard, set the [C++ Language Standard](../build/reference/std-specify-language-standard-version.md) option to the desired standard and fix any compile errors that are raised. In general, we recommend setting the language standard to [/std:c++17](../build/reference/std-specify-language-standard-version.md). The errors raised when upgrading to a newer standard are not related to the errors raised when using the **permissive-** option.
18+
19+
- Code that conforms to all versions of the standard but is no longer considered best practice in modern C++.
20+
21+
To identify code where changes are recommended, run [Code analysis](/visualstudio/code-quality/code-analysis-for-c-cpp-overview).
22+
23+
## Open and convert a legacy project
24+
25+
If your legacy project is based on an older version of Visual Studio, you can open it in Visual Studio 2017 or Visual Studio 2019. Visual Studio automatically converts it to the current project schema with support for all the latest compiler and IDE features.
26+
27+
![Upgrade a project](media/upgrade-dialog-v142.png "Upgrade a project")
28+
29+
For more information, see [Upgrade C++ projects from earlier versions of Visual Studio](upgrading-projects-from-earlier-versions-of-visual-cpp.md).
30+
31+
## Search the code base
32+
33+
Upgrading a code base often involves searching through multiple files. To search for anything in your code base, press **Ctrl+T** to bring up the **Go to All** search box.
34+
35+
![Go to all](media/go-to-all.png "Go to all")
36+
37+
To narrow the search scope, type one of the 1-letter filters, followed by a space and then the thing you are looking for.
38+
39+
## Error List
40+
41+
After you set the desired C++ Language Standard and any other compiler options (**Project** > **Properties** > **General**), press **Ctrl+Shift+B** to compile your project. You can expect to see some errors and warnings in the form of red squiggles in various places in the code. The errors also appear in the **Error List**. For more information about an specific error, click on the error code to go to the help page in the documentation. Error codes that begin with a "C" are compiler errors. Codes that begin with "MSB" are MSBuild errors that indicate a problem with the project configuration.
42+
43+
![Compiler and MSBuild errors in Error List](media/compiler-error-list.png "Compiler and MSBuild errors in Error List")
44+
45+
## Document Health Indicator
46+
47+
The document health indicator at the bottom of the editor shows the number of errors and warnings in the current document, and enables you to navigate directly from one warning/error to the next.
48+
49+
![Document health indicator](media/document-health-indicator.png "Document health indicator")
50+
51+
In many cases, you can find more information about a specific error in the documentation on the Visual Studio change history and conformance improvements.
52+
53+
- [C++ conformance improvements](../overview/cpp-conformance-improvements.md)
54+
- [Visual C++ Change History 2003 - 2015](visual-cpp-change-history-2003-2015.md)
55+
- [Overview of potential upgrade issues](overview-of-potential-upgrade-issues-visual-cpp.md)
56+
57+
## Use code analysis to modernize your code
58+
59+
When upgrading, we recommend that you run code analysis on your project so that the code, conforms at a minimum to the Microsoft Native Recommended Rules. These rules are a combination of rules defined by Microsoft and a subset of the [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines). By conforming to these you will greatly reduce or eliminate common sources of bugs, and at the same time make your code more readable and therefore easier to maintain. Code Analysis using the Microsoft Native Recommended Rules is enabled by default. You can enable additional rules under **Project** > **Properties** > **Code Analysis**. Code that violates one of the rules is flagged as a warning and is underlined with a green squiggle in the code editor. Hover over the squiggle to see a **QuickInfo** tooltip that describes the issue.
60+
61+
![Code analysis tooltip](media/code-analysis-tooltip.png "Code analysis warning")
62+
63+
Click on the filter icon in the **Code** column to choose which warnings are displayed.
64+
65+
![Code analysis filters in Error List](media/code-analysis-filter.png "Code analysis filters in Error List")
66+
67+
Code analysis errors and warnings also appear in the **Error List** just like compiler errors.
68+
69+
![Code analysis warnings in Error List](media/code-analysis-error-list.png "Code analysis warnings in Error List")
70+
71+
You can change which rules are active, and create custom rulesets. For more information about using Code Analysis, see [Code analysis for C/C++ overview](/visualstudio/code-quality/code-analysis-for-c-cpp-overview).
72+
73+
## Use Quick Actions to modernize code
74+
75+
The code editor provides Quick Actions for some common recommendations. When the light bulb icon is displayed, you can click on it to see the available Quick Actions.
76+
77+
### Convert macros to constexpr functions
78+
79+
The following image shows the use of macro called `AVERAGE`, which has the default semantic colorization. The image also shows the QuickInfo tooltip that is displayed when the mouse cursor hovers over it:
80+
81+
![QuickInfo macro expansion](media/macro-expansion-quick-info.png "QuickInfo tooltip macro expansion")
82+
83+
Because the use of macros is discouraged in modern C++, Visual Studio makes it easy to convert macros to **constexpr** functions:
84+
85+
1. Right-click on `AVERAGE` and choose **Go to Definition**.
86+
2. Click on the screwdriver icon and choose **Convert macro to constexpr**
87+
88+
![Quick Action macro to constexpr](media/quick-action-macro-to-constexpr.png "Quick Action macro to constexpr")
89+
90+
The macro is converted as shown below:
91+
92+
![constexpr function](media/constexpr-function.png "constexpr function")
93+
94+
And the call to `AVERAGE` is now colorized as a function call, and the Quick Info tooltip shows the deduced type of the function:
95+
96+
![constexpr function call](media/constexpr-function-call.png "constexpr function call")
97+
98+
### Initialize variables
99+
100+
Uninitialized variables can hold random values that lead to serious bugs. Code analysis flags these instances, and the editor provides a Quick Action:
101+
102+
![Initialize variable](media/init-variable.png "Initialize variable Quick Action")
103+
104+
### Convert to raw string literal
105+
106+
Raw string literals are less error-prone and more convenient to type than strings with embedded escape characters. Right-click on a string and choose **Quick Actions** to convert it to a raw string literal.
107+
108+
![Raw string literal](media/raw-string-literal.png "Raw string literal")
109+
110+
The string is converted to: `R"(C:\Users\bjarnes\demo\output.txt)"`.
Loading
19 KB
Loading
66.6 KB
Loading
15.6 KB
Loading
20.4 KB
Loading
17.6 KB
Loading
17 KB
Loading
23.6 KB
Loading

docs/porting/media/go-to-all.png

7.21 KB
Loading

docs/porting/media/init-variable.png

14.4 KB
Loading
Loading
Loading
14.7 KB
Loading
13.4 KB
Loading

docs/porting/visual-cpp-porting-and-upgrading-guide.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Microsoft C++ Porting and Upgrading Guide"
33
description: "Upgrade Microsoft C++ code to the latest version of Visual Studio."
4-
ms.date: "10/29/2019"
4+
ms.date: "11/05/2019"
55
ms.assetid: f5fbcc3d-aa72-41a6-ad9a-a706af2166fb
66
ms.topic: "overview"
77
---
@@ -19,7 +19,7 @@ If a legacy application is running satisfactorily, in a secure environment, and
1919

2020
- The same code can run faster due to improved compiler optimizations.
2121

22-
- Modern C++ features and programming practices eliminate many common causes of bugs and is far easier to maintain that older C-style idioms.
22+
- Modern C++ features and programming practices eliminate many common causes of bugs and produce code that is far easier to maintain than older C-style idioms.
2323

2424
- Build times are significantly faster, due to performance improvements in the compiler and linker.
2525

@@ -42,6 +42,7 @@ For more information, see [Use native multi-targeting in Visual Studio to build
4242
|Title|Description|
4343
|-----------|-----------------|
4444
|[Upgrading C++ projects from earlier versions of Visual Studio](upgrading-projects-from-earlier-versions-of-visual-cpp.md)|How to upgrade your code base to Visual Studio 2019 and v142 of the compiler.|
45+
|[IDE tools for upgrading C++ code](ide-tools-for-upgrading-code.md)|Useful IDE features that help in the upgrade process.|
4546
|[C++ Binary Compatibility between 2015 and 2019](binary-compat-2015-2017.md)|Consume v140 libraries as-is from v142 projects.|
4647
|[Use native multi-targeting in Visual Studio to build old projects](use-native-multi-targeting.md)|Use Visual Studio 2019 with older compilers and libraries.|
4748
|[Visual C++ change history 2003 - 2015](visual-cpp-change-history-2003-2015.md)|A list of all the changes in the Microsoft C++ libraries and build tools from Visual Studio 2003 through 2015 that might require changes in your code.|

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,6 +2848,8 @@
28482848
href: porting/porting-third-party-libraries.md
28492849
- name: Port data applications
28502850
href: data/data-access-programming-mfc-atl.md
2851+
- name: IDE tools for upgrading C++ code
2852+
href: porting/ide-tools-for-upgrading-code.md
28512853
- name: Visual C++ change history 2003 - 2015
28522854
href: porting/visual-cpp-change-history-2003-2015.md
28532855
- name: Visual C++ What's New 2003 through 2015

0 commit comments

Comments
 (0)