Visual Studio 中的 C++ 新变化What's new for C++ in Visual Studio

Visual Studio 2019 向 Microsoft C++ 环境引入了许多更新和修补程序。Visual Studio 2019 brings many updates and fixes to the Microsoft C++ environment. 我们修复了编译器和工具中存在的许多 bug 和问题。We've fixed many bugs and issues in the compiler and tools. 其中许多问题是客户通过“发送反馈”下的报告问题提供建议选项提交的。Many of these issues were submitted by customers through the Report a Problem and Provide a Suggestion options under Send Feedback. 感谢你报告 bug!Thank you for reporting bugs! 有关所有 Visual Studio 中新增功能的详细信息,请访问 Visual Studio 2019 中的新增功能For more information on what's new in all of Visual Studio, visit What's new in Visual Studio 2019. 有关 Visual Studio 2017 中 C++ 新增功能的信息,请参阅 Visual Studio 2017 中 C++ 的新增功能For information on what's new for C++ in Visual Studio 2017, see What's new for C++ in Visual Studio 2017. 有关 Visual Studio 2015 及更低版本中 C++ 新增功能的信息,请参阅 Visual C++ 新增功能 (2003 - 2015)For information on what's new for C++ in Visual Studio 2015 and earlier versions, see Visual C++ What's New 2003 through 2015.

有关 C++ 文档中新增功能的信息,请参阅 Microsoft C++ 文档:新增功能For information about what's new in the C++ docs, see Microsoft C++ docs: What's new.

C++ 编译器C++ compiler

  • 增强了对 C++17 功能和正确性修复的支持,以及对 C++20 功能(如模块和协同例程)的实验性支持。Enhanced support for C++17 features and correctness fixes, plus experimental support for C++20 features such as modules and coroutines. 有关详细信息,请参阅 Visual Studio 2019 中 C++ 的符合性改进For detailed information, see C++ Conformance Improvements in Visual Studio 2019.

  • /std:c++latest 选项现在包含 C++20 功能(不一定完整),包括对用于三向比较的 C++20 宇宙飞船运算符 <=> 的初始支持。The /std:c++latest option now includes C++20 features that aren't necessarily complete, including initial support for the C++20 operator <=> ("spaceship") for three-way comparison.

  • C++ 编译器开关 /Gm 现已弃用。The C++ compiler switch /Gm is now deprecated. 如果已显式定义,请考虑在生成脚本中禁用 /Gm 交换机。Consider disabling the /Gm switch in your build scripts if it's explicitly defined. 但也可以安全地忽略针对 /Gm 的弃用警告,因为在使用“将警告视为错误”(/WX) 时不会将其视为错误。However, you can also safely ignore the deprecation warning for /Gm, because it's not treated as an error when using "Treat warnings as errors" (/WX).

  • 随着 MSVC 开始在 /std:c++latest 标志下实现 C++20 标准草案中的功能,/std:c++latest 现与 /clr(所有版本)、/ZW/Gm 不兼容。As MSVC begins implementing features from the C++20 standard draft under the /std:c++latest flag, /std:c++latest is now incompatible with /clr (all flavors), /ZW, and /Gm. 在 Visual Studio 2019 中,请在使用 /clr/ZW/Gm 编译时使用 /std:c++17/std:c++14 模式(请参阅上一项目符号)。In Visual Studio 2019, use /std:c++17 or /std:c++14 modes when compiling with /clr, /ZW, or /Gm (but see previous bullet).

  • 对于 C++ 控制台和桌面应用,默认情况下不再生成预编译头文件。Precompiled headers are no longer generated by default for C++ console and desktop apps.

Codegen、安全性、诊断和版本控制Codegen, security, diagnostics, and versioning

借助用于为 Spectre Variant 1 提供迁移缓解的 /Qspectre 改进分析 (CVE-2017-5753)。Improved analysis with /Qspectre for providing mitigation assistance for Spectre Variant 1 (CVE-2017-5753). 有关详细信息,请参阅 MSVC 中的 Spectre 缓解措施For more information, see Spectre Mitigations in MSVC.

C++ 标准库改进C++ standard library improvements

  • 实现了其他 C++17 和 C++20 库功能和正确性修复。Implementation of additional C++17 and C++20 library features and correctness fixes. 有关详细信息,请参阅 Visual Studio 2019 中 C++ 的符合性改进For detailed information, see C++ Conformance Improvements in Visual Studio 2019.

  • Clang-Format 已应用于 C++ 标准库标头,以提高可读性。Clang-Format has been applied to the C++ standard library headers for improved readability.

  • 由于 Visual Studio 现在支持用于 C++ 的“仅我的代码”,因此标准库不再需要为 std::functionstd::visit 提供自定义机制,即可实现相同效果。Because Visual Studio now supports Just My Code for C++, the standard library no longer needs to provide custom machinery for std::function and std::visit to achieve the same effect. 删除此机制在很大程度上对用户没有明显影响。Removing that machinery largely has no user-visible effects. 只是编译器不再生成诊断来指明 <type_traits> 或 <variant> 的行 15732480 或 16707566 存在问题。One exception is that the compiler will no longer produce diagnostics that indicate issues on line 15732480 or 16707566 of <type_traits> or <variant>.

编译器和标准库中的性能提升/吞吐量改进Performance/throughput improvements in the compiler and standard library

  • 改进生成吞吐量,包括 PDB 类型合并和创建过程中,链接器对文件 I/O 和链接时间的处理方式。Build throughput improvements, including the way the linker handles File I/O, and link time in PDB type merging and creation.

  • 添加了对 OpenMP SIMD 矢量化的基本支持。Added basic support for OpenMP SIMD vectorization. 可以使用新的编译器开关 /openmp:experimental 来启用它。You can enable it using the new compiler switch /openmp:experimental. 此选项可能使带 #pragma omp simd 注释的循环被矢量化。This option allows loops annotated with #pragma omp simd to potentially be vectorized. 无法保证矢量化,已注释但未矢量化的循环将收到系统警告。The vectorization isn't guaranteed, and loops annotated but not vectorized will get a warning reported. 不支持 SIMD 子句,它们将被忽略并报告警告。No SIMD clauses are supported; they're ignored, and a warning is reported.

  • 新增了内联命令行开关 /Ob3,它是 /Ob2 的更厉害版本。Added a new inlining command-line switch /Ob3, which is a more aggressive version of /Ob2. /O2(优化二进制代码来提高速度)仍默认暗指 /Ob2/O2 (optimize the binary for speed) still implies /Ob2 by default. 如果发现编译器内联得不够厉害,可以考虑传递 /O2 -Ob3If you find that the compiler doesn't inline aggressively enough, consider passing /O2 -Ob3.

  • 现已开始支持 Short Vector Math Library (SVML) 内部函数。We've added support for Short Vector Math Library (SVML) intrinsic functions. 这些函数计算 128 位、256 位或 512 位的向量等效项。These functions compute the 128-bit, 256-bit, or 512-bit vector equivalents. 支持此类函数是为了支持手动矢量化循环,循环中包含对数学库函数的调用和某些其他运算(如整数除法)。We added them to support hand vectorization of loops with calls to math library functions, and certain other operations like integer division. 有关支持的函数的定义,请参阅 Intel 内部函数指南See the Intel Intrinsic Guide for definitions of the supported functions.

  • 新的和已改进的优化:New and improved optimizations:

    • 可使用 SIMD 矢量内部函数简化表达式的常量合并和算法(针对浮点和整数形式)。Constant-folding and arithmetic simplifications for expressions using SIMD vector intrinsics, for both float and integer forms.

    • 提供更强大的分析功能,帮助从控制流(if/else/switch 语句)中提取信息以删除被证明为 true 或 false 的分支。A more powerful analysis for extracting information from control flow (if/else/switch statements) to remove branches always proven to be true or false.

    • 改进了 memset 展开,以使用 SSE2 矢量指令。Improved memset unrolling to use SSE2 vector instructions.

    • 改进了无用 struct/class 副本(特别是针对按值传递的 C++ 程序)的删除操作。Improved removal of useless struct/class copies, especially for C++ programs that pass by value.

    • 使用 memmove(例如 std::copystd::vectorstd::string 构造)优化代码的过程。Improved optimization of code using memmove, such as std::copy or std::vector and std::string construction.

  • 优化标准库物理设计,以避免不直接包含标准库的编译部分。Optimized the standard library physical design to avoid compiling parts of the standard library not directly included. 此更改将只包含 <vector> 的空文件的生成时间缩短了一半。This change cut the build time of an empty file that includes only <vector> in half. 因此,可能需要为之前间接包含的标头添加 #include 指令。As a consequence, you may need to add #include directives for headers that were previously indirectly included. 例如,现在可能需要为使用 std::out_of_range 的代码添加 #include <stdexcept>For example, code that uses std::out_of_range may now need to add #include <stdexcept>. 现在可能需要为使用流插入运算符的代码添加 #include <ostream>Code that uses a stream insertion operator may now need to add #include <ostream>. 这样做的好处是,只有真正使用 <stdexcept> 或 <ostream> 组件的转换单元,才需要支付吞吐量费用来编译它们。The benefit is that only translation units actually using <stdexcept> or <ostream> components pay the throughput cost to compile them.

  • if constexpr 已应用于标准库中的多个位置,用于在复制操作、反向和旋转等排列操作和并行算法库中提高吞吐量并缩减代码大小。if constexpr was applied in more places in the standard library for improved throughput and reduced code size in copy operations, in permutations like reverse and rotate, and in the parallel algorithms library.

  • 标准库现在内部使用 if constexpr 来缩短编译时间,即使是在 C++14 模式下,也不例外。The standard library now internally uses if constexpr to reduce compile times, even in C++14 mode.

  • 并行算法库的运行时动态链接检测不再使用整个页面来存储函数指针数组。The runtime dynamic linking detection for the parallel algorithms library no longer uses an entire page to store the function pointer array. 将此内存设为只读被视为不再与安全目的相关。Marking this memory read-only was considered no longer relevant for security purposes.

  • std::thread 的构造函数不再等待线程启动,并且不再在基础 C 库 _beginthreadex 和提供的可调用对象之间插入太多函数调用层。std::thread's constructor no longer waits for the thread to start, and no longer inserts so many layers of function calls between the underlying C library _beginthreadex and the supplied callable object. 以前,std::thread_beginthreadex 和所提供的可调用对象之间放置了六个函数。Previously std::thread put six functions between _beginthreadex and the supplied callable object. 这个数字已经减少到只有三个,其中两个就是 std::invokeThis number has been reduced to only three, two of which are just std::invoke. 此更改还修复了一个难处理的计时 bug,即当系统时钟恰好在创建 std::thread 的时刻更改时,std::thread 构造函数会停止响应。This change also resolves an obscure timing bug, where a std::thread constructor would stop responding if the system clock changed at the exact moment the std::thread was being created.

  • 修复了实现 std::hash<std::filesystem::path> 时引入的 std::hash 中的性能回归。Fixed a performance regression in std::hash that we introduced when implementing std::hash<std::filesystem::path>.

  • 标准库现在在多个位置使用析构函数(而不是 catch 块)来实现正确性。The standard library now uses destructors instead of catch blocks in several places to achieve correctness. 此更改改进了调试程序交互:通过标准库在受影响位置上引发的异常,现在显示为从它们的原始引发站点引发,而不是由我们重新引发。This change results in better debugger interaction: Exceptions you throw through the standard library in the affected locations now show up as being thrown from their original throw site, rather than our rethrow. 并不是所有标准库 catch 块都被消除了。Not all standard library catch blocks were eliminated. 我们期望在 MSVC 的后续版本中减少 catch 块的数量。We expect the number of catch blocks to be reduced in later releases of MSVC.

  • noexcept 函数内的条件抛出导致 std::bitset 中出现的不理想 codegen 已通过析出抛出路径得以修复。Suboptimal codegen in std::bitset caused by a conditional throw inside a noexcept function was fixed by factoring out the throwing path.

  • std::liststd::unordered_* 系列在多个位置内部使用非调试迭代器。The std::list and std::unordered_* family use non-debugging iterators internally in more places.

  • 多个 std::list 成员已更改为尽可能重用列表节点,而不是解除分配和重新分配它们。Several std::list members were changed to reuse list nodes where possible rather than deallocating and reallocating them. 例如,假定 list<int> 的大小已经为 3,对 assign(4, 1729) 的调用现在覆盖前 3 个列表节点中的整数,并分配一个包含值 1729 的新列表节点。For example, given a list<int> that already has a size of 3, a call to assign(4, 1729) now overwrites the ints in the first three list nodes, and allocates one new list node with the value 1729.

  • 所有对 erase(begin(), end()) 的标准库调用都已更改为 clear()All standard library calls to erase(begin(), end()) were changed to clear().

  • 在某些情况下,std::vector 现在可以更高效地初始化并清除元素。std::vector now initializes and erases elements more efficiently in certain cases.

  • std::variant 进行了改进,使其更易于优化,从而更好地生成代码。Improvements to std::variant to make it more optimizer-friendly, resulting in better generated code. 借助 std::visit,现在可更好地进行代码内联。Code inlining is now much better with std::visit.

C++ IDEC++ IDE

Live Share C++ 支持Live Share C++ support

Live Share 现在支持 C++,使开发者可以使用 Visual Studio 或 Visual Studio Code 进行实时协作。Live Share now supports C++, allowing developers using Visual Studio or Visual Studio Code to collaborate in real time. 有关详细信息,请参阅 Announcing Live Share for C++:Real-Time Sharing and Collaboration(宣布推出用于 C++ 的 Live Share:实时共享和协作)For more information, see Announcing Live Share for C++: Real-Time Sharing and Collaboration

适用于 C++ 的 IntelliCodeIntelliCode for C++

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

IntelliCode 使用它自己的广泛训练和你的代码上下文,将你最有可能使用的内容置于完成列表的最上面。IntelliCode uses its own extensive training and your code context to put what you're most likely to use at the top of your completion list. 它通常可使用户无需向下滚动列表。It can often eliminate the need to scroll down through the list. 对于 C++,IntelliCode 可在使用标准库等热门库时提供最大帮助。For C++, IntelliCode offers the most help when using popular libraries such as the standard library. IntelliCode 是一个可选扩展,可作为安装程序中的工作负载组件。IntelliCode is an optional extension available as a workload component in the installer. 有关详细信息,请参阅 AI-Assisted Code Completion Suggestions Come to C++ via IntelliCode(AI 辅助的代码完成建议通过 IntelliCode 提供给 C++)。For more information, see AI-Assisted Code Completion Suggestions Come to C++ via IntelliCode.

模板 IntelliSenseTemplate IntelliSense

“模板栏”现使用“速览窗口”用户界面而不是模式窗口,它支持嵌套模板,并且可以将任何默认参数预先填充到“速览窗口”中 。The Template Bar now uses the Peek Window UI rather than a modal window, supports nested templates, and pre-populates any default arguments into the Peek Window. 有关详细信息,请参阅 Template IntelliSense Improvements for Visual Studio 2019 Preview 2(Visual Studio 2019 预览版 2 的模板 IntelliSense 改进)。For more information, see Template IntelliSense Improvements for Visual Studio 2019 Preview 2. 借助“模板栏”中的“最近使用”下拉列表,可以在以前的示例参数集之间快速切换 。A Most Recently Used dropdown in the Template Bar enables you to quickly switch between previous sets of sample arguments.

新启动窗口体验New Start window experience

启动 IDE 时,会看到一个新的“启动”窗口。When launching the IDE, a new Start window appears. 在其中可以打开最近使用的项目、从源代码管理克隆代码、将本地代码作为解决方案或文件夹打开,也可以新建项目。It has options to open recent projects, clone code from source control, open local code as a solution or a folder, or create a new project. “新项目”对话框也已彻底改造为一种搜索优先的可筛选体验。The New Project dialog has also been overhauled into a search-first, filterable experience.

某些项目模板的新名称New names for some project templates

我们修改了几个项目模板名称和描述以适应更新的“新建项目”对话框。We've modified several project template names and descriptions to fit with the updated New Project dialog.

多种工作效率提升Various productivity improvements

Visual Studio 2019 包含以下功能,有助于使编码更简单、更直观:Visual Studio 2019 includes the following features that will help make coding easier and more intuitive:

  • 快速修复:Quick fixes for:
    • 添加缺少的 #includeAdd missing #include
    • NULL 到 nullptrNULL to nullptr
    • 添加缺少的分号Add missing semicolon
    • 解析缺少的命名空间或范围Resolve missing namespace or scope
    • 替换错误的间接操作数(* 替换为 & 和 & 替换为 *)Replace bad indirection operands (* to & and & to *)
  • 通过悬停在右大括号上,获取块的快速信息Quick Info for a block by hovering on closing brace
  • 速览标题/代码文件Peek Header / Code File
  • 转到 #include 上的定义可打开文件Go to Definition on #include opens the file

有关详细信息,请参阅 C++ Productivity Improvements in Visual Studio 2019 Preview 2(Visual Studio 2019 预览版 2 中的 C++ 生产力改进)。For more information, see C++ Productivity Improvements in Visual Studio 2019 Preview 2.

快速信息改进QuickInfo improvements

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

快速信息工具提示现在遵循编辑器的语义着色。The Quick Info tooltip now respects the semantic colorization of your editor. 它还新增了“联机搜索”链接,可便于搜索联机文档来详细了解鼠标悬停于其上的代码构造。It also has a new Search Online link that will search for online docs to learn more about the hovered code construct. 快速信息为带红色波浪线的代码提供的链接会联机搜索相应错误。The link provided by Quick Info for red-squiggled code will search for the error online. 这样,就不需要在浏览器中重新键入消息。That way you don't need to retype the message into your browser. 有关详细信息,请参阅 Visual Studio 2019 中的快速信息改进:着色和联机搜索For more information, see Quick Info Improvements in Visual Studio 2019: Colorization and Search Online.

IntelliCode 可用于 C++ 工作负荷IntelliCode available in C++ workload

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

IntelliCode 现在作为“使用 C++ 的桌面开发”工作负荷中的可选组件提供。IntelliCode now ships as an optional component in the Desktop Development with C++ workload. 有关详细信息,请参阅 Visual Studio 2019 现在随附改进后的 C++ IntelliCodeFor more information, see Improved C++ IntelliCode now Ships with Visual Studio 2019.

CMake 支持CMake support

  • 支持 CMake 3.14Support for CMake 3.14

  • Visual Studio 现可打开由外部工具(如 CMakeGUI)、自定义元构建系统或自行调用 cmake.exe 的构生成脚本生成的现有 CMake 缓存。Visual Studio can now open existing CMake caches generated by external tools, such as CMakeGUI, customized meta-build systems or build scripts that invoke cmake.exe themselves.

  • 改进了 IntelliSense 性能。Improved IntelliSense performance.

  • 新的设置编辑器提供了手动编辑 CMakeSettings.json 文件的替代方案,并且可进行一些 CMakeGUI 奇偶校验。A new settings editor provides an alternative to manually editing the CMakeSettings.json file, and provides some parity with CMakeGUI.

  • Visual Studio 可检测 Linux 计算机上是否具有兼容的 CMake 版本,从而帮助你在 Linux 上使用 CMake 启动 C++ 开发。Visual Studio helps bootstrap your C++ development with CMake on Linux by detecting if you have a compatible version of CMake on your Linux machine. 如果没有兼容的版本,它会自行安装。If not, it offers to install it for you.

  • CMakeSettings 中不兼容的设置(例如不匹配的体系结构或不兼容的 CMake 生成器设置)在 JSON 编辑器中显示为波形曲线,并在错误列表中显示错误。Incompatible settings in CMakeSettings, such as mismatched architectures or incompatible CMake generator settings, show squiggles in the JSON editor and errors in the error list.

  • 对于运行 vcpkg integrate install 后在 IDE 中打开的 CMake 项目,将自动为其检测并启用 vcpkg 工具链。The vcpkg toolchain is automatically detected and enabled for CMake projects that are opened in the IDE once vcpkg integrate install has been run. 可通过在 CMakeSettings 中指定空工具链文件来关闭此行为。This behavior can be turned off by specifying an empty toolchain file in CMakeSettings.

  • CMake 项目现默认启用“仅我的代码”调试。CMake projects now enable Just My Code debugging by default.

  • 静态分析警告现在后台进行处理,并显示在 CMake 项目的编辑器中。Static analysis warnings are now processed in the background and displayed in the editor for CMake projects.

  • 针对 CMake 项目更明晰的有关生成和配置的“开始”及“结束”消息,以及对 Visual Studio 生成进度用户界面的支持。Clearer build and configure 'begin' and 'end' messages for CMake projects and support for Visual Studio's build progress UI. 此外,“工具”>“选项”中现提供 CMake 详细级别设置,用于在输出窗口中自定义 CMake 生成和配置消息的详细级别。Additionally, there's now a CMake verbosity setting in Tools > Options to customize the detail level of CMake build and configuration messages in the Output Window.

  • CMakeSettings.json 现支持 cmakeToolchain 设置,无需手动修改 CMake 命令行即可指定工具链。The cmakeToolchain setting is now supported in CMakeSettings.json to specify toolchains without manually modifying the CMake command line.

  • 新的“全部生成”菜单快捷方式 Ctrl+Shift+B 。A new Build All menu shortcut Ctrl+Shift+B.

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

Linux 和适用于 Linux 的 Windows 子系统Linux and the Windows Subsystem for Linux

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

IncrediBuild 集成IncrediBuild integration

IncrediBuild 现在添加为“使用 C++ 的桌面开发”工作负荷中的可选组件。IncrediBuild is included as an optional component in the Desktop development with C++ workload. IncrediBuild 生成监视器已完全集成在 Visual Studio IDE 中。The IncrediBuild Build Monitor is fully integrated in the Visual Studio IDE. 有关详细信息,请参阅使用 IncrediBuild 的生成监视器和 Visual Studio 2019 直观呈现生成For more information, see Visualize your build with IncrediBuild's Build Monitor and Visual Studio 2019.

调试Debugging

  • 对于在 Windows 上运行的 C++ 应用程序,PDB 文件现可在单独的 64 位进程中加载。For C++ applications running on Windows, PDB files now load in a separate 64-bit process. 此更改解决了由于调试程序内存不足而导致的一系列故障。This change addresses a range of crashes caused by the debugger running out of memory. 例如,在调试包含大量模块和 PDB 文件的应用程序时。For example, when debugging applications that contain a large number of modules and PDB files.

  • “监视”、“自动”和“本地”窗口中启用了搜索功能。Search is enabled in the Watch, Autos, and Locals windows.

使用 C++ 的 Windows 桌面开发Windows desktop development with C++

  • 这些 C++ ATL/MFC 向导不再可用:These C++ ATL/MFC wizards are no longer available:

    • ATL COM+ 1.0 组件向导ATL COM+ 1.0 Component Wizard
    • ATL Active Server Pages 组件向导ATL Active Server Pages Component Wizard
    • ATL OLE DB 提供程序向导ATL OLE DB Provider Wizard
    • ATL 属性页向导ATL Property Page Wizard
    • ATL OLE DB 使用者向导ATL OLE DB Consumer Wizard
    • MFC ODBC 使用者MFC ODBC Consumer
    • ActiveX 控件中的 MFC 类MFC class from ActiveX control
    • Type Lib 中的 MFC 类。MFC class from Type Lib.

    这些技术的示例代码存档在 Microsoft Docs 和 VCSamples GitHub 存储库中。Sample code for these technologies is archived at Microsoft Docs and the VCSamples GitHub repository.

  • Visual Studio 安装程序中不再提供 Windows 8.1 软件开发工具包 (SDK)。The Windows 8.1 Software Development Kit (SDK) is no longer available in the Visual Studio installer. 建议将 C++ 项目升级到最新的 Windows 10 SDK。We recommend you upgrade your C++ projects to the latest Windows 10 SDK. 如果在 8.1 上具有硬依赖项,则可以从 Windows SDK 存档下载它。If you have a hard dependency on 8.1, you can download it from the Windows SDK archive.

  • Windows XP 目标将不再适用于最新的 C++ 工具集。Windows XP targeting will no longer be available for the latest C++ toolset. 仍支持使用 VS 2017 级 MSVC 编译器和库的 XP 目标定向,并且可通过“单个组件”进行安装。XP targeting with VS 2017-level MSVC compiler & libraries is still supported and can be installed via "Individual components."

  • 我们的文档不推荐使用 Merge 模块部署 Visual C++ 运行时。Our documentation actively discourages usage of Merge Modules for Visual C++ Runtime deployment. 此版本执行了额外步骤,将 MSM 标记为已弃用。We're taking the extra step this release of marking our MSMs as deprecated. 请考虑将 VCRuntime 核心部署从 MSM 迁移到可再发行组件包。Consider migrating your VCRuntime central deployment from MSMs to the redistributable package.

使用 C++ 的移动开发(Android 和 iOS)Mobile development with C++ (Android and iOS)

现在,C++ Android 体验默认为 Android SDK 25 和 Android NDK 16b。The C++ Android experience now defaults to Android SDK 25 and Android NDK 16b.

Clang/C2 平台工具集Clang/C2 platform toolset

已删除 Clang/C2 实验性组件。The Clang/C2 experimental component has been removed. 使用 MSVC 工具集,以完全符合 /permissive-/std:c++17 的 C++ 标准,或者适用于 Windows 的 Clang/LLVM 工具链。Use the MSVC toolset for full C++ standards conformance with /permissive- and /std:c++17, or the Clang/LLVM toolchain for Windows.

代码分析Code analysis

Visual Studio 2019 版本 16.1Visual Studio 2019 version 16.1

单元测试Unit testing

托管的 C++ 测试项目模板不再可用。The Managed C++ Test Project template is no longer available. 可在现有项目中继续使用托管的 C++ 测试框架。You can continue using the Managed C++ Test framework in your existing projects. 对于新的单元测试,请考虑使用 Visual Studio 为其提供模板(MSTest、Google Test)或托管的 C# 测试项目模板的某个本机测试框架。For new unit tests, consider using one of the native test frameworks for which Visual Studio provides templates (MSTest, Google Test), or the Managed C# Test Project template.

Visual Studio 2017 向 C++ 环境引入了许多更新和修补程序。Visual Studio 2017 brings many updates and fixes to the C++ environment. 我们修复了编译器和工具中存在的 250 多个缺陷和报告的问题。We've fixed over 250 bugs and reported issues in the compiler and tools. 许多问题是客户通过“发送反馈”下的“报告问题和提供建议”选项提交的。Many were submitted by customers through the Report a Problem and Provide a Suggestion options under Send Feedback. 感谢你报告 bug!Thank you for reporting bugs! 有关整个 Visual Studio 中新增功能的详细信息,请参阅 Visual Studio 2017 中的新增功能For more information on what's new in all of Visual Studio, see What's new in Visual Studio 2017. 有关 Visual Studio 2019 中 C++ 新增功能的信息,请参阅 Visual Studio 中 C++ 的新增功能For information on what's new for C++ in Visual Studio 2019, see What's new for C++ in Visual Studio. 有关 Visual Studio 2015 及更低版本中 C++ 新增功能的信息,请参阅 Visual C++ 新增功能 (2003 - 2015)For information on what's new for C++ in Visual Studio 2015 and earlier versions, see Visual C++ What's New 2003 through 2015.

Visual Studio 2017 C++ 编译器Visual Studio 2017 C++ compiler

C++ 的符合性改进C++ conformance improvements

我们在此版本中更新了 C++ 编译器和标准库,增强了对 C++11 和 C++14 功能的支持。We've updated the C++ compiler and standard library in this release with enhanced support for C++11 and C++14 features. 它还包括对 C++17 标准中预计会有的某些功能的初步支持。It also includes preliminary support for certain features expected to be in the C++17 standard. 有关详细信息,请参阅 Visual Studio 2017 中 C++ 的符合性改进For detailed information, see C++ Conformance Improvements in Visual Studio 2017.

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

编译器支持 C++17 中约 75% 的新功能,其中包括结构化绑定、constexpr Lambda、if constexpr、内联变量、折叠表达式以及将 noexcept 添加到类型系统。The compiler supports about 75% of the features that are new in C++17, including structured bindings, constexpr lambdas, if constexpr, inline variables, fold expressions, and adding noexcept to the type system. 可通过 /std:c++17 选项使用这些功能。These features are available under the /std:c++17 option. 有关详细信息,请参阅 Visual Studio 2017 中 C++ 的符合性改进For more information, see C++ Conformance Improvements in Visual Studio 2017

Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

Visual Studio 15.7 版中的 MSVC 编译器工具集现符合 C++ 标准。The MSVC compiler toolset in Visual Studio version 15.7 now conforms with the C++ Standard. 有关详细信息,请参阅公告:MSVC 符合 C++ 标准Microsoft C++ 语言合规性For more information, see Announcing: MSVC Conforms to the C++ Standard and Microsoft C++ Language Conformance.

Visual Studio 2017 版本 15.8Visual Studio 2017 version 15.8

/experimental:preprocessor 编译器开关启用了新的实验性 MSVC 预处理器,它最终将符合所有适用的 C 和 C++ 标准。The /experimental:preprocessor compiler switch enables the new experimental MSVC preprocessor that will eventually conform to all applicable C and C++ standards. 有关详细信息,请参阅 MSVC 新预处理器概述For more information, see MSVC new preprocessor overview.

新的编译器选项New compiler options

  • /permissive-:启用所有严格标准符合性编译器选项,并禁用大部分特定于 Microsoft 的编译器扩展(但有一些例外,比如 __declspec(dllimport))。/permissive-: Enable all strict standards conformance compiler options and disable most Microsoft-specific compiler extensions (but not __declspec(dllimport), for example). 在 Visual Studio 2017 15.5 版中此选项默认为开启状态。This option is on by default in Visual Studio 2017 version 15.5. /permissive- 符合性模式支持两阶段名称查找。The /permissive- conformance mode includes support for two-phase name lookup. 有关详细信息,请参阅 Visual Studio 中 C++ 的符合性改进For more information, see C++ Conformance Improvements in Visual Studio.

  • /diagnostics:可通过三种不同的方式来显示诊断错误或警告位置:只显示行号;显示行号和列;或显示行号和列,并在违规代码行下方显示脱字号。/diagnostics: Enables display of the diagnostic error or warning location three different ways: just the line number, the line number and column, or the line number and column, with a caret under the offending line of code.

  • /debug:fastlink:通过避免将所有调试信息复制到 PDB 文件,实现最高达 30% 更快的增量链接时间(与Visual Studio 2015 相比)。/debug:fastlink: Enable up to 30% faster incremental link times (vs. Visual Studio 2015) by not copying all debug information into the PDB file. PDB 文件改为指向用于创建可执行文件的对象和库文件的调试信息。The PDB file instead points to the debug information for the object and library files used to create the executable. 请参阅使用 /Debug:fastlink 在 VS “15”中缩短 C++ 生成周期在 Visual Studio 中加速 C++ 生成的建议See Faster C++ build cycle in VS "15" with /Debug:fastlink and Recommendations to speed C++ builds in Visual Studio.

  • Visual Studio 2017 允许结合使用 /sdl/awaitVisual Studio 2017 allows using /sdl with /await. 删除了针对协同例程的 /RTC 限制。We removed the /RTC limitation with Coroutines.

Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • /std:c++14/std:c++latest:通过这些编译器开关可选择在项目中加入特定版本的 ISO C++ 编程语言。/std:c++14 and /std:c++latest: These compiler options enable you to opt in to specific versions of the ISO C++ programming language in a project. 大多数新的草案标准功能由 /std:c++latest 选项保护。Most of the new draft standard features are guarded by the /std:c++latest option.

  • 借助 /std:c++17,可以使用编译器实现的一组 C++17 功能。/std:c++17 enables the set of C++17 features implemented by the compiler. 此选项禁用编译器和标准库对 C++17 之后功能的支持:在工作草案的后续版本中更改或新增的功能,以及 C++ 标准的缺陷更新。This option disables compiler and standard library support for features after C++17: ones that are changed or new in later versions of the Working Draft, and defect updates of the C++ Standard. 若要启用这些功能,请使用 /std:c++latestTo enable those features, use /std:c++latest.

Codegen、安全性、诊断和版本控制Codegen, security, diagnostics, and versioning

此版本在优化、代码生成、工具集版本控制和诊断方面做出了若干改进。This release brings several improvements in optimization, code generation, toolset versioning, and diagnostics. 显著改进包括:Some notable improvements include:

  • 改进了循环的代码生成:支持常量整数除法的自动矢量化,优化了 memset 模式的识别。Improved code generation of loops: Support for automatic vectorization of division of constant integers, better identification of memset patterns.
  • 提高了代码安全性:改进了缓冲区溢出编辑器诊断的输出,/guard:cf 现在保护生成转移表的 switch 语句。Improved code security: Improved emission of buffer overrun compiler diagnostics, and /guard:cf now guards switch statements that generate jump tables.
  • 版本控制:现在,每次更新 Visual C++ 工具集时都将单调更新内置预处理器宏 _MSC_VER 的值。Versioning: The value of the built-in preprocessor macro _MSC_VER is now being monotonically updated at every Visual C++ toolset update. 有关详细信息,请参阅 Visual C++ Compiler Version(Visual C++ 编译器版本)。For more information, see Visual C++ Compiler Version.
  • 新工具集布局:编译器和相关生成工具在开发计算机上有了新的位置和目录结构。New toolset layout: The compiler and related build tools have a new location and directory structure on your development machine. 新布局支持并行安装多个版本的编译器。The new layout enables side-by-side installations of multiple versions of the compiler. 有关详细信息,请参阅 Visual Studio 2017 中的编译器工具布局For more information, see Compiler Tools Layout in Visual Studio 2017.
  • 改进了诊断:输出窗口现在会显示发生错误的列。Improved diagnostics: The output window now shows the column where an error occurs. 有关详细信息,请参阅 C++ compiler diagnostics improvements in VS “15” Preview 5(VS“15”预览版 5 中的 C++ 编译器诊断改进)。For more information, see C++ compiler diagnostics improvements in VS "15" Preview 5.
  • 当使用协同例程时,(“/await”选项下的)实验性关键字“yield”已被删除。When using coroutines, the experimental keyword yield (available under the /await option) has been removed. 应更新代码,以改为使用 co_yieldYour code should be updated to use co_yield instead. 有关详细信息,请参阅 VS 2017 中的 yield 关键字变为 co_yieldFor more information, see yield keyword to become co_yield in VS 2017.
Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3

针对编辑器中的诊断的其他改进。Additional improvements to diagnostics in the compiler. 有关详细信息,请参阅 Visual Studio 2017 15.3.0 中的诊断改进For more information, see Diagnostic Improvements in Visual Studio 2017 15.3.0.

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

通过提高生成的代码质量,Visual C++ 运行时性能不断提升。Visual C++ runtime performance continues to improve through better generated code quality. 现在只需重新编译代码,即可加快应用的运行速度。Now you can just recompile your code, and your app runs faster. 编译器的某些优化是前所未有的,例如条件标量存储的矢量化,将 sin(x)cos(x) 调用合并到新的 sincos(x) 中,以及删减了 SSA 优化器中多余的说明。Some of the compiler optimizations are brand new, such as the vectorization of conditional scalar stores, the combining of calls sin(x) and cos(x) into a new sincos(x), and the elimination of redundant instructions from the SSA optimizer. 其他编译器优化是对现有功能进行了改进,如条件表达式的矢量化器启发、改进了循环优化和浮动最小/最大 CodeGen。Other compiler optimizations are improvements to existing functionality, such as: vectorizer heuristics for conditional expressions, better loop optimizations, and float min/max codegen. 链接器有一个更快的新 /OPT:ICF 实现,最多可带来 9% 的链接时间加速,并且在增量链接中还有其他性能修复。The linker has a new and faster /OPT:ICF implementation, which can result in up to 9% link-time speedups, and there are other perf fixes in incremental linking. 有关详细信息,请参阅 /OPT(优化)/INCREMENTAL(增量链接)For more information, see /OPT (Optimizations) and /INCREMENTAL (Link Incrementally).

Microsoft C++ 编译器支持 Intel AVX-512。The Microsoft C++ compiler supports Intel's AVX-512. 它有矢量长度指令,可以将 AVX-512 中的新函数引入 128 位宽和 256 位宽的寄存器。It has Vector Length instructions that bring new functions in AVX-512 to 128-bit and 256-bit wide registers.

通常,在使用 C++17 模式时,可使用 /Zc:noexceptTypes- 选项恢复到 noexcept 的 C++14 版本。The /Zc:noexceptTypes- option can be used to revert to the C++14 version of noexcept while using C++17 mode in general. 此选项可以将源代码更新为符合 C++17,而无需同时重写所有 throw() 代码。This option enables you to update your source code to conform to C++17 without having to rewrite all your throw() code at the same time. 有关详细信息,请参阅动态异常规范的删除和 noexceptFor more information, see Dynamic exception specification removal and noexcept.

Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

C++ 标准库C++ standard library

正确性改进Correctness Improvements

Visual Studio 2017 RTM(版本 15.0)Visual Studio 2017 RTM (version 15.0)
  • 次要 basic_string``_ITERATOR_DEBUG_LEVEL != 0 诊断改进。Minor basic_string _ITERATOR_DEBUG_LEVEL != 0 diagnostics improvements. 当 IDL 检查在字符串机制中失误时,它现在会报告导致失误的特定行为。When an IDL check gets tripped in string machinery, it will now report the specific behavior that caused the trip. 例如,现在会收到“无法取消引用字符串迭代器,因为其已超出范围(例如末尾迭代器)”,而不是“字符串迭代器不可取消引用”。For example, instead of "string iterator not dereferencable" you'll get "cannot dereference string iterator because it is out of range (e.g. an end iterator)".
  • 修复了会导致代码永久受阻的 std::promise 移动赋值运算符。Fixed the std::promise move assignment operator, which previously could cause code to block forever.
  • 修复了编译器错误,将 atomic<T*> 隐式转换为 T*Fixed compiler errors with the atomic<T*> implicit conversion to T*.
  • pointer_traits<Ptr> 现可正确检测 Ptr::rebind<U>pointer_traits<Ptr> now correctly detects Ptr::rebind<U>.
  • 修复了 move_iterator 减法运算符中缺少 const 限定符的问题。Fixed a missing const qualifier in the move_iterator subtraction operator.
  • 在需要 propagate_on_container_copy_assignmentpropagate_on_container_move_assignment 的用户定义的有状态分配器中,修复了损坏的无效 codegen。Fixed silent bad codegen for stateful user-defined allocators requesting propagate_on_container_copy_assignment and propagate_on_container_move_assignment.
  • atomic<T> 现可容忍重载的 operator&()atomic<T> now tolerates overloaded operator&().
  • 对于错误的 bind() 调用,略微改进了其编译器诊断。Slightly improved compiler diagnostics for incorrect bind() calls.

Visual Studio 2017 RTM 中有更多的标准库改进。There are more standard library improvements in Visual Studio 2017 RTM. 有关完整列表,请参阅 C++ 团队博客条目 VS 2017 RTM 中的标准库修补程序For a complete list, see the C++ Team Blog entry Standard Library Fixes In VS 2017 RTM.

Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 标准库容器现将其 max_size()(而非 size_typemax())固定到 numeric_limits<difference_type>::max() 中。Standard library containers now clamp their max_size() to numeric_limits<difference_type>::max() rather than the max() of size_type. 此更改可确保迭代器上来自该容器的 distance() 的结果可使用 distance() 的返回类型表示。This change ensures that the result of distance() on iterators from that container is representable in the return type of distance().
  • 修复了缺少专用化 auto_ptr<void> 的问题。Fixed missing specialization auto_ptr<void>.
  • 以前,如果 length 参数不是整型类型,for_each_n()generate_n()search_n() 算法就无法进行编译。The for_each_n(), generate_n(), and search_n() algorithms previously failed to compile if the length argument wasn't an integral type. 现在,它们尝试将非整型长度转换为迭代器的 difference_typeThey now attempt to convert non-integral lengths to the iterators' difference_type.
  • normal_distribution<float> 不再在标准库中发出关于从双精度型收缩为浮点型的警告。normal_distribution<float> no longer emits warnings inside the standard library about narrowing from double to float.
  • 修复了一些在检查最大大小溢出时使用 npos 而不是 max_size()basic_string 操作。Fixed some basic_string operations that used npos instead of max_size() when checking for maximum size overflow.
  • 以前,condition_variable::wait_for(lock, relative_time, predicate) 会在出现虚假唤醒时等待整个相对时间。condition_variable::wait_for(lock, relative_time, predicate) would wait for the entire relative time if there was a spurious wake. 现在,它只等待单个相对时间间隔。Now it waits for only a single interval of the relative time.
  • future::get() 现按标准版要求,使 future 失效。future::get() now invalidates the future, as the standard requires.
  • iterator_traits<void *> 曾经是一个硬错误,它尝试形成 void&;而现在,它完全变成了一个空结构,允许在 “is iterator”SFINAE 条件中使用 iterator_traitsiterator_traits<void *> used to be a hard error because it attempted to form void&; it now cleanly becomes an empty struct to allow use of iterator_traits in "is iterator" SFINAE conditions.
  • 修复了 Clang -Wsystem-headers 报告的一些警告。Some warnings reported by Clang -Wsystem-headers were fixed.
  • 还修复了 Clang -Wmicrosoft-exception-spec 报告的“声明中的异常规范与以前的声明不匹配”这一问题。Also fixed "exception specification in declaration does not match previous declaration" reported by Clang -Wmicrosoft-exception-spec.
  • 还修复了 Clang 和 C1XX 报告的 mem-initializer-list 排序警告。Also fixed mem-initializer-list ordering warnings reported by Clang and C1XX.
  • 当容器本身交换时,无序容器不会交换其哈希函数或谓词。The unordered containers didn't swap their hash functions or predicates when the containers themselves were swapped. 现在它们会进行交换。Now they do.
  • 现在,许多容器交换操作都被标记为 noexcept(因为标准库从未打算在检测到非 propagate_on_container_swap 不相等分配器未定义的行为条件时抛出异常)。Many container swap operations are now marked noexcept (as our standard library never intends to throw an exception when detecting the non-propagate_on_container_swap non-equal-allocator undefined behavior condition).
  • 许多 vector<bool> 操作现在都被标记为 noexceptMany vector<bool> operations are now marked noexcept.
  • 标准库现在将使用选择退出的转义交错线来强制执行匹配的分配器 value_type(在 C++17 模式中)。The standard library will now enforce matching allocator value_type (in C++17 mode) with an opt-out escape hatch.
  • 修复了一些将 self-range 插入 basic_string 会打乱字符串内容的情况。Fixed some conditions where self-range-insert into basic_string would scramble the strings contents. (注意:标准库仍禁止将 self-range 插入到矢量)。(Note: self-range-insert into vectors is still prohibited by the Standard.)
  • basic_string::shrink_to_fit() 不再受分配器的 propagate_on_container_swap 影响。basic_string::shrink_to_fit() is no longer affected by the allocator's propagate_on_container_swap.
  • std::decay 现可处理令人烦恼的函数类型(即 cv 限定和/或 ref 限定的函数类型)。std::decay now handles abominable function types, that is, function types that are cv-qualified, ref-qualified, or both.
  • 更改了 include 指令以正确使用区分大小写和正斜杠,从而提高可移植性。Changed include directives to use proper case sensitivity and forward slashes, improving portability.
  • 修复了警告 C4061“枚举‘enumeration’的 switch 中的枚举器‘enumerator’未按 case 标签进行显式处理”。Fixed warning C4061 "enumerator 'enumerator' in switch of enum 'enumeration' is not explicitly handled by a case label". 此警告默认关闭,并且已作为标准库警告常规策略的一个异常进行了修复。This warning is off-by-default and was fixed as an exception to the standard library's general policy for warnings. (标准库是不含 /W4,但并不会试图不含 /Wall(The standard library is /W4 clean, but doesn't attempt to be /Wall clean. 许多默认关闭的警告的干扰性都异常高,不打算经常使用。)Many off-by-default warnings are unusually noisy, and aren't intended to be used on a regular basis.)
  • 改进了 std::list 调用检查。Improved std::list debug checks. 列表迭代器现检查 operator->(),且 list::unique() 现将迭代器标记为无效。List iterators now check operator->(), and list::unique() now marks iterators as invalidated.
  • 修复了元组中的 tuple 元编程。Fixed uses-allocator metaprogramming in tuple.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • std::partition 现在调用谓词 N 次,而不是 N + 1 次(按标准要求)。std::partition now calls the predicate N times instead of N + 1 times, as the standard requires.
  • 已在版本 15.5 中修复版本 15.3 中避免神奇的静态对象的尝试。Attempts to avoid magic statics in version 15.3 have been repaired in version 15.5.
  • std::atomic<T> 不再需要 T 默认可构造。std::atomic<T> no longer requires T to be default constructible.
  • 在迭代器调试启用后,需要使用对数时间的堆算法的行为有所不同。Heap algorithms that take logarithmic time behave differently when iterator debugging is enabled. 它们不再做输入实际上是堆的线性时间断言。They no longer do a linear time assertion that the input is in fact a heap.
  • __declspec(allocator) 现仅针对 C1XX 进行保护,防止出现来自不了解此 declspec 的 Clang 的警告。__declspec(allocator) is now guarded for C1XX only, to prevent warnings from Clang, which doesn't understand this declspec.
  • basic_string::npos 现在可作为编译时常数提供。basic_string::npos is now available as a compile time constant.
  • C++17 模式中的 std::allocator 现在正确处理过度对齐的类型(即其对齐高于 max_align_t 的类型)的分配,除非由 /Zc:alignedNew- 禁用。std::allocator in C++17 mode now properly handles allocation of over-aligned types, that is, types whose alignment is greater than max_align_t, unless disabled by /Zc:alignedNew-. 例如,对于 SSE 和 AVX 说明,现在将正确对齐采用 16 或 32 字节对齐的对象的矢量。For example, vectors of objects with 16-byte or 32-byte alignment are now properly aligned for SSE and AVX instructions.

符合性改进Conformance improvements

  • 我们添加了 <any>、<string_view>、apply()make_from_tuple()We added <any>, <string_view>, apply(), make_from_tuple().
  • 添加了 <optional>、<variant>、shared_ptr::weak_type 和 <cstdalign>。Added <optional>, <variant>, shared_ptr::weak_type, and <cstdalign>.
  • min(initializer_list)max(initializer_list)minmax(initializer_list)min_element()max_element()minmax_element() 中启用了 C++14 constexprEnabled C++14 constexpr in min(initializer_list), max(initializer_list), and minmax(initializer_list), and min_element(), max_element(), and minmax_element().

有关详细信息,请参阅 Microsoft C++ 语言一致性表For more information, see Microsoft C++ language conformance table.

Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 已经实现了几个其他的 C++17 功能。Several additional C++17 features have been implemented. 有关详细信息,请参阅 Microsoft C++ 语言一致性表For more information, see Microsoft C++ language conformance table.
  • 实现了 P0602R0“变体和可选项应传播副本/移动琐碎事项”。Implemented P0602R0 "variant and optional should propagate copy/move triviality".
  • 现在,标准库正式允许通过 /GR- 选项禁用动态 RTTI。The standard library now officially tolerates dynamic RTTI being disabled via the /GR- option. 由于 dynamic_pointer_cast()rethrow_if_nested() 本质上都需要 dynamic_cast,因此标准库现在将它们标记为 /GR- 下的 =deleteBoth dynamic_pointer_cast() and rethrow_if_nested() inherently require dynamic_cast, so the standard library now marks them as =delete under /GR-.
  • 即使已通过 /GR- 禁用了动态 RTTI,“静态 RTTI”(采用 typeid(SomeType) 形式)仍可用,并为多个标准库组件提供技术支持。Even when dynamic RTTI has been disabled via /GR-, "static RTTI" in the form of typeid(SomeType) is still available, and powers several standard library components. 现在,标准库也支持通过 /D_HAS_STATIC_RTTI=0 禁用此功能。The standard library now supports disabling this feature too, via /D_HAS_STATIC_RTTI=0. 此标志还将禁用 std::anystd::functiontarget()target_type() 成员函数,以及 std::shared_ptrstd::weak_ptrget_deleter() 友元成员函数。This flag also disables std::any, the target() and target_type() member functions of std::function, and the get_deleter() friend member function of std::shared_ptr and std::weak_ptr.
  • 标准库现在无条件地使用 C++14 constexpr,而不是有条件定义的宏。The standard library now uses C++14 constexpr unconditionally, instead of conditionally defined macros.
  • 标准库现在内部使用别名模板。The standard library now uses alias templates internally.
  • 标准库现在内部使用 nullptr,而不是 nullptr_t{}The standard library now uses nullptr internally, instead of nullptr_t{}. (已根除 NULL 的内部使用。(Internal usage of NULL has been eradicated. 正在逐渐清理 0 作为 null 的内部使用。)Internal usage of 0-as-null is being cleaned up gradually.)
  • 标准库现在内部使用 std::move(),而不是在风格上误用 std::forward()The standard library now uses std::move() internally, instead of stylistically misusing std::forward().
  • static_assert(false, "message") 更改为了 #error messageChanged static_assert(false, "message") to #error message. 此更改提高了编译器诊断,因为 #error 立即停止编译。This change improves compiler diagnostics because #error immediately stops compilation.
  • 标准库不再将函数标记为 __declspec(dllimport)The standard library no longer marks functions as __declspec(dllimport). 新式链接器技术不再需要此操作。Modern linker technology no longer requires it.
  • 已将 SFINAE 提取到默认模板参数,与返回类型和函数参数类型相比,这可以减少混乱。Extracted SFINAE to default template arguments, which reduced clutter compared to return types and function argument types.
  • <random> 中的调试检查现在使用标准库的常用机制,而不是使用将 fputs() 调用到 stderr 的内部函数 _Rng_abort()Debug checks in <random> now use the standard library's usual machinery, instead of the internal function _Rng_abort(), which called fputs() to stderr. 此函数的实现是为了二进制兼容性而保留的。This function's implementation has been kept for binary compatibility. 我们将在下一个二进制不兼容版本的标准库中删除它。We'll remove it in the next binary-incompatible version of the standard library.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • 根据 C++17 标准,添加、弃用或删除了多个标准库功能。Several standard library features have been added, deprecated, or removed per the C++17 standard. 有关详细信息,请参阅 Visual Studio 中 C++ 的符合性改进For more information, see C++ conformance improvements in Visual Studio.
  • 以下并行算法的实验支持:Experimental support for the following parallel algorithms:
    • all_of
    • any_of
    • for_each
    • for_each_n
    • none_of
    • reduce
    • replace
    • replace_if
    • sort
  • 添加了以下并行算法的签名,但暂未进行并行化。The signatures for the following parallel algorithms are added but not parallelized at this time. 分析表明,只移动或重新排列元素的并行算法并无益处:Profiling showed no benefit in parallelizing algorithms that only move or permute elements:
    • copy
    • copy_n
    • fill
    • fill_n
    • move
    • reverse
    • reverse_copy
    • rotate
    • rotate_copy
    • swap_ranges
Visual Studio 2017 版本 15.6Visual Studio 2017 version 15.6
  • <memory_resource>
  • Library Fundamentals V1Library Fundamentals V1
  • 正在删除 polymorphic_allocator 分配Deleting polymorphic_allocator assignment
  • 改进类模板参数推导Improving class template argument deduction
Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7
  • 对并行算法的支持不再是实验性的Support for parallel algorithms is no longer experimental
  • <filesystem> 的新实现A new implementation of <filesystem>
  • 基本字符串转换(部分)Elementary string conversions (partial)
  • std::launder()
  • std::byte
  • hypot(x,y,z)
  • 避免不必要的衰减Avoiding unnecessary decay
  • 数学特殊函数Mathematical special functions
  • constexpr char_traits
  • 标准库的推导指南Deduction guides for the standard library

有关详细信息,请参阅 Microsoft C++ 语言一致性表For more information, see Microsoft C++ language conformance table.

性能和吞吐量修复Performance and throughput fixes

  • 仅在调用 traits::find 一次后执行 basic_string::find(char) 重载。Made basic_string::find(char) overloads only call traits::find once. 以前会将此操作实施为针对长度为 1 的字符串的常规字符串搜索。Previously, it was implemented as a general string search for a string of length 1.
  • basic_string::operator== 现先检查字符串的大小,然后再比较字符串的内容。basic_string::operator== now checks the string's size before comparing the strings' contents.
  • 删除了 basic_string 中编译器优化程序难以分析的控制耦合。Removed control coupling in basic_string, which was difficult for the compiler optimizer to analyze. 对任意短字符串调用 reserve 时,即使不执行操作,也会耗费资源。For all short strings, calling reserve still has a nonzero cost to do nothing.
  • 为了提高正确性和性能,std::vector 已全面改进:现可按标准版的要求正确处理在插入和安置操作期间的别名,在标准版需要时现可通过 move_if_noexcept() 和其他逻辑提供强异常保证,且减少了插入和安置所执行的元素操作。std::vector has been overhauled for correctness and performance: aliasing during insert and emplace operations is now correctly handled as required by the Standard, the strong exception guarantee is now provided when required by the Standard via move_if_noexcept() and other logic, and insert and emplace do fewer element operations.
  • 现在 C++ 标准库会避免取消引用 null 复杂精致指针。The C++ standard library now avoids dereferencing null fancy pointers.
  • 提升了 weak_ptr::lock() 性能。Improved weak_ptr::lock() performance.
  • 为提高编译器吞吐量,C++ 标准库标头现不会包含非必需编译器内部函数的声明。To increase compiler throughput, C++ standard library headers now avoid including declarations for unnecessary compiler intrinsics.
  • std::stringstd::wstring 移动构造函数的性能提升了三倍以上。Improved the performance of std::string and std::wstring move constructors by more than three times.
Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 解决了与 noexcept 的交互,避免了将 std::atomic 实现内联到使用结构化异常处理 (SEH) 的函数中。Worked around interactions with noexcept, which prevented inlining the std::atomic implementation into functions that use Structured Exception Handling (SEH).
  • 更改了标准库的内部 _Deallocate() 函数,优化为较小的代码,从而能将其内联到更多的位置。Changed the standard library's internal _Deallocate() function to optimize into smaller code, allowing it to be inlined into more places.
  • 更改了 std::try_lock() 以使用包扩展,而不是递归。Changed std::try_lock() to use pack expansion instead of recursion.
  • 改进了 std::lock() 的死锁避免算法以使用 lock() 操作,而不是在所有锁的 try_lock() 上旋转。Improved the std::lock() deadlock avoidance algorithm to use lock() operations instead of spinning on try_lock() on all the locks.
  • system_category::message() 中实现了命名返回值优化。Enabled the Named Return Value Optimization in system_category::message().
  • conjunctiondisjunction 现在实例化 N + 1 类型,而不是 2N + 2 类型。conjunction and disjunction now instantiate N + 1 types, instead of 2N + 2 types.
  • std::function 不再实例化每个类型擦除的可调用项的分配器支持机制,从而提高吞吐量,并缩减将许多不同的 lambda 传递给 std::function 的程序中的 .obj 大小。std::function no longer instantiates allocator support machinery for each type-erased callable, improving throughput and reducing .obj size in programs that pass many distinct lambdas to std::function.
  • allocator_traits<std::allocator> 包含自动内联的 std::allocator 操作,从而缩减仅通过 allocator_traitsstd::allocator 交互的代码中的代码大小(即在大部分代码中)。allocator_traits<std::allocator> contains manually inlined std::allocator operations, reducing code size in code that interacts with std::allocator through allocator_traits only (that is, in most code).
  • C++11 最小分配器接口现在由标准库直接调用 allocator_traits 进行处理,而不是将分配器包装在内部类 _Wrap_alloc 中。The C++11 minimal allocator interface is now handled by the standard library calling allocator_traits directly, instead of wrapping the allocator in an internal class _Wrap_alloc. 此更改减少了为分配器支持生成的代码大小,提高了优化器在某些情况下对标准库容器进行推理的能力,并提供了更好的调试体验(正如现在看到了分配器类型,而不是调试器中的 _Wrap_alloc<your_allocator_type>)。This change reduces the code size generated for allocator support, improves the optimizer's ability to reason about standard library containers in some cases, and provides a better debugging experience (as now you see your allocator type, rather than _Wrap_alloc<your_allocator_type> in the debugger).
  • 删除了自定义 allocator::reference 的元编程,不允许自定义分配器。Removed metaprogramming for customized allocator::reference, which allocators aren't allowed to customize. (分配器可以使容器使用设想的指针,但不可以使用设想的引用。)(Allocators can make containers use fancy pointers but not fancy references.)
  • 编译器前端已学会在基于范围的 for 循环中展开调试迭代器,从而提高调试版本的性能。The compiler front end was taught to unwrap debug iterators in range-based for loops, improving the performance of debug builds.
  • shrink_to_fit()reserve()basic_string 内部收缩路径不再位于重新分配操作的路径中,从而减少所有转变成员的代码大小。The basic_string internal shrink path for shrink_to_fit() and reserve() is no longer in the path of reallocating operations, reducing code size for all mutating members.
  • basic_string 的内部增长路径不再位于 shrink_to_fit() 的路径中。The basic_string internal grow path is no longer in the path of shrink_to_fit().
  • basic_string 的转变操作现在已纳入到非分配快速路径和分配慢速路径函数,从而使其更有可能将常见的无重新分配的情况内联到调用方中。The basic_string mutating operations are now factored into non-allocating fast path and allocating slow path functions, making it more likely for the common no-reallocate case to be inlined into callers.
  • basic_string 的转变操作现在构造首选状态的重新分配的缓冲区,而不是就地调整大小。The basic_string mutating operations now construct reallocated buffers in the preferred state rather than resizing in place. 例如,如果在字符串开头插入,现在只在插入后移动内容一次。For example, an insert at the beginning of a string now moves the content after the insertion exactly once. 它要么向下移动,要么移动到新分配的缓冲区。It's moved either down or to the newly allocated buffer. 在重新分配的情况下,它不再移动两次(即先移动到新分配的缓冲区,再向下移动)。It's no longer moved twice in the reallocating case, first to the newly allocated buffer and then down.
  • 在 <string> 中调用 C 标准库的操作现在缓存 errno 的地址以消除与 TLS 的重复交互。Operations calling the C standard library in <string> now cache the errno address to remove repeated interaction with TLS.
  • 简化了 is_pointer 实现。Simplified the is_pointer implementation.
  • 完成了将基于函数的表达式 SFINAE 更改为基于 structvoid_tFinished changing function-based Expression SFINAE to struct and void_t-based.
  • 标准库算法现在避免使用后增量迭代器。Standard library algorithms now avoid postincrementing iterators.
  • 修复了在 64 位系统上使用 32 位分配器时的截断警告。Fixed truncation warnings when using 32-bit allocators on 64-bit systems.
  • 通过重复使用缓冲区(如果可能),在非 POCMA 非等分配器情况下,std::vector 移动赋值现在更高效。std::vector move assignment is now more efficient in the non-POCMA non-equal-allocator case, by reusing the buffer when possible.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • basic_string<char16_t> 现与 basic_string<wchar_t> 占用相同的 memcmpmemcpy 和类似优化。basic_string<char16_t> now engages the same memcmp, memcpy, and similar optimizations that basic_string<wchar_t> engages.
  • 已暂时避开阻止函数指针被 Visual Studio 2015 Update 3“避免复制函数”工作内联公开的优化器限制,从而还原 lower_bound(iter, iter, function pointer) 的性能。An optimizer limitation that prevented function pointers from being inlined, exposed by our "avoid copying functions" work in Visual Studio 2015 Update 3, has been worked around, restoring performance of lower_bound(iter, iter, function pointer).
  • 将迭代器解包后再检查顺序,降低了向 includesset_differenceset_symmetric_differenceset_union 的输入执行迭代器调试顺序验证的开销。The overhead of iterator debugging's order verification of inputs to includes, set_difference, set_symmetric_difference, and set_union was reduced by unwrapping iterators before checking order.
  • std::inplace_merge 现在跳过已就位的元素。std::inplace_merge now skips over elements that are already in position.
  • 构造 std::random_device 时不再构造再销毁 std::stringConstructing std::random_device no longer constructs and then destroys a std::string.
  • std::equalstd::partition 有跳转线程优化传递,可以免去一次迭代器比较。std::equal and std::partition had a jump-threading optimization pass that saves an iterator comparison.
  • std::reverse 将指针传递到完全可复制的 T 时,它将分派至一个手写的矢量化实现。When std::reverse is passed pointers to trivially copyable T, it will now dispatch to a handwritten vectorized implementation.
  • 过去,std::fillstd::equalstd::lexicographical_compare 被指示如何调度到 std::bytegsl::bytememsetmemcmp(及其他类似 char 的枚举和 enum 类)。std::fill, std::equal, and std::lexicographical_compare were taught how to dispatch to memset and memcmp for std::byte and gsl::byte (and other char-like enums and enum classes). 由于 std::copy 使用 is_trivially_copyable 进行调度,因此无需任何更改。Since std::copy dispatches using is_trivially_copyable, it didn't need any changes.
  • 标准库不再包含仅有的行为是使类型不完全易损坏的空大括号析构函数。The standard library no longer contains empty-braces destructors whose only behavior was to make types non-trivially-destructible.

其他库Other Libraries

开源库支持Open-source library support

Vcpkg 是一款开源命令行工具,能极大简化在 Visual Studio 中获取和生成开源 C++ 静态库和 DLLS 的过程。Vcpkg is an open-source command-line tool that greatly simplifies the process of acquiring and building open-source C++ static libs and DLLS in Visual Studio. 有关详细信息,请参阅vcpkg:适用于 C++ 的包管理器For more information, see vcpkg: A package manager for C++.

CPPRest SDK 2.9.0CPPRest SDK 2.9.0

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

CPPRestSDK(C++ 的跨平台 Web API)已更新到版本 2.9.0。The CPPRestSDK, a cross-platform web API for C++, has been updated to version 2.9.0. 有关详细信息,请参阅 CppRestSDK 2.9.0 is available on GitHub(GitHub 上提供了 CppRestSDK 2.9.0)。For more information, see CppRestSDK 2.9.0 is available on GitHub.

ATLATL

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • 另外进行了另一组名称查找符合性修复Yet another set of name-lookup conformance fixes
  • 现有的移动构造函数和移动赋值运算符现已正确地标记为非引发Existing move constructors and move assignment operators are now properly marked as non-throwing
  • 取消禁止有关 atlstr.h 中本地静态变量的线程安全初始化的有效警告 C4640Unsuppress valid warning C4640 about thread safe init of local statics in atlstr.h
  • 以前,在使用 ATL 生成 DLL 时,本地静态变量的线程安全初始化在 XP 工具集中自动关闭。Thread-safe initialization of local statics was automatically turned off in the XP toolset when using ATL to build a DLL. 现在不是。Now it's not. 如果不需要线程安全初始化,则可以在“项目”设置中添加 /Zc:threadSafeInit-You can add /Zc:threadSafeInit- in your Project settings if you don't want thread-safe initialization.

Visual C++ 运行时Visual C++ runtime

  • 为控制流防护符号新增了标头“cfguard.h”。New header "cfguard.h" for Control Flow Guard symbols.

Visual Studio 2017 C++ IDEVisual Studio 2017 C++ IDE

  • 现针对 C++ 本机项目和 C++ /CLI 项目有了更佳的配置更改性能,后者的性能增加更为明显。Configuration change performance is now better for C++ native projects and much better for C++/CLI projects. 第一次激活解决方案配置时,现在的速度会更快,且此解决方案配置的所有后续激活几乎可瞬时完成。When a solution configuration is activated for the first time, it will now be faster, and all later activations of this solution configuration will be almost instantaneous.
Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 多个项目和代码向导已按照签名对话框样式重新编写。Several project and code wizards have been rewritten in the signature dialog style.
  • “添加类”现在直接启动“添加类向导”。Add Class now launches the Add Class wizard directly. 以前此处的其他所有项现在位于“添加”>“新建项”。All of the other items that were previously here are now available under Add > New Item.
  • Win32 项目现位于“新建项目”对话框中的“Windows 桌面”类别下 。Win32 projects are now under the Windows Desktop category in the New Project dialog.
  • Windows 控制台和桌面应用程序模板现可在不显示向导的情况下创建项目 。The Windows Console and Desktop Application templates now create the projects without displaying a wizard. 现在,在相同类别下有一个新的 Windows 桌面向导,显示与旧版 Win32 控制台应用程序向导相同的选项 。There's a new Windows Desktop Wizard under the same category that displays the same options as the old Win32 Console Application wizard.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

多种使用 IntelliSense 引擎重构和导航代码的 C++ 操作运行速度更快。Several C++ operations that use the IntelliSense engine for refactoring and code navigation run much faster. 以下数字基于有 3500 个项目的 Visual Studio Chromium 解决方案:The following numbers are based on the Visual Studio Chromium solution with 3500 projects:

功能Feature 性能改进Performance Improvement
重命名Rename 5.3 倍5.3x
更改签名Change Signature 4.5 倍4.5x
查找所有引用Find All References 4.7 倍4.7x

C++ 现在支持通过“Ctrl+单击”转到定义,使利用鼠标导航到定义更轻松。C++ now supports Ctrl+Click Go To Definition, making mouse navigation to definitions easy. Productivity Power Tools 包的结构可视化工具现在也默认包含在产品中。The Structure Visualizer from the Productivity Power Tools pack is now also included in the product by default.

IntelliSenseIntelliSense

  • 现在默认使用全新的基于 SQLite 的数据库引擎。The new SQLite-based database engine is now being used by default. 新引擎加快了数据库操作(如“转到定义”和“查找所有引用”)的速度。The new engine speeds up database operations like Go To Definition and Find All References. 它显著缩短了初始解决方案分析时间。It significantly improves initial solution parse time. 此设置已移动到“工具”>“选项”>“文本编辑器”>“C/C++”>“高级”。The setting has moved to Tools > Options > Text Editor > C/C++ > Advanced. (它以前位于...“C/C++”>“实验性”下。)(It was formerly under ...C/C++ > Experimental.)

  • 我们改进了不使用预编译标头的项目和文件的 IntelliSense 性能 - 为当前文件中的标头创建自动预编译标头。We've improved IntelliSense performance on projects and files not using precompiled headers - an Automatic Precompiled Header will be created for headers in the current file.

  • 还为错误列表中的 IntelliSense 错误添加了错误筛选和帮助。We've added error filtering and help for IntelliSense errors in the error list. 单击错误列现在允许进行筛选。Clicking on the error column now allows for filtering. 此外,单击特定错误或按 F1 将启动错误消息的联机搜索。Also, clicking on the specific errors or pressing F1 will launch an online search for the error message.

    错误列表Error List

    筛选的错误列表Error List Filtered

  • 增添了按类型筛选“成员列表”项的功能。Added the ability to filter Member List items by kind.

    成员列表筛选Member List Filtering

  • 添了新的实验性预测 IntelliSense 功能,此功能可根据上下文筛选成员列表中的所示内容。Added a new experimental Predictive IntelliSense feature that provides contextually aware filtering of what appears in the Member List. 有关详细信息,请参阅 C++ IntelliSense 改进 - 预测 IntelliSense 和筛选For more information, see C++ IntelliSense Improvements - Predictive IntelliSense & Filtering.

  • 即使在复杂基本代码中,“查找所有引用”(Shift+F12) 现在也可帮助轻松进行查找。Find All References (Shift+F12) now helps you get around easily, even in complex codebases. 它提供高级分组、筛选、排序、在结果中搜索以及(适用于某些语言的)着色,以便你清楚了解自己的引用。It provides advanced grouping, filtering, sorting, searching within results, and (for some languages) colorization, so you can get a clear understanding of your references. 对于 C++ 而言,新的 UI 包括有关是否要从变量读取或向其写入的信息。For C++, the new UI includes information about whether we're reading from or writing to a variable.

  • 已将“点到箭头”IntelliSense 功能从实验级提升为高级,且现在为默认启用。The Dot-to-Arrow IntelliSense feature has been moved from experimental to advanced, and is now enabled by default. 编辑器功能“展开作用域”和“展开优先级”也已从实验级提升为高级 。The editor features Expand Scopes and Expand Precedence have also been moved from experimental to advanced.

  • 实验性的重构功能“更改签名”和“提取函数”现默认可用 。The experimental refactoring features Change Signature and Extract Function are now available by default.

  • 添加了面向 C++ 项目的实验性“快速项目加载”功能。Added an experimental 'Faster project load' feature for C++ projects. 下次打开 C++ 项目时,加载速度将更快,而再下一次的加载速度要快得多!The next time you open a C++ project it will load faster, and the time after that it will load much faster!

  • 其中一些功能与其他语言通用,有些则特定于 C++。Some of these features are common to other languages, and some are specific to C++. 有关这些新增功能的详细信息,请参阅发布 Visual Studio“15”预览版 5For more information about these new features, see Announcing Visual Studio "15" Preview 5.

Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

包含“打开文件夹”的非 MSBuild 项目Non-MSBuild projects with Open Folder

Visual Studio 2017 引入了“打开文件夹”功能。Visual Studio 2017 introduces the Open Folder feature. 这样,可以在包含源代码的文件夹中进行编码、生成和调试,而无需创建任何解决方案或项目。It enables you to code, build, and debug in a folder containing source code without the need to create any solutions or projects. 现在使用 Visual Studio 变得更简单,即使你的项目不基于 MSBuild 也是如此。Now it's much simpler to get started with Visual Studio, even if your project isn't an MSBuild-based project. 使用“打开文件夹”,可以访问强大的代码理解、编辑、生成和调试功能。Open Folder gives you access to powerful code understanding, editing, building, and debugging capabilities. 这些是 Visual Studio 已为 MSBuild 项目提供的功能。They're the same ones that Visual Studio already provides for MSBuild projects. 有关详细信息,请参阅 C++ 的“打开文件夹”项目For more information, see Open Folder projects for C++.

  • 改进了“打开文件夹”体验。Improvements to the Open Folder experience. 可通过以下 .json 文件自定义体验:You can customize the experience through these .json files:
    • 使用 CppProperties.json 可自定义 IntelliSense 和浏览体验。CppProperties.json to customize the IntelliSense and browsing experience.
    • 使用 Tasks.json 可自定义生成步骤。Tasks.json to customize the build steps.
    • 使用 Launch.json 可自定义调试体验。Launch.json to customize the debugging experience.
Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 改进了对备用编译器和生成环境(如 MinGW 和 Cygwin)的支持。Improved support for alternative compilers and build environments such as MinGW and Cygwin. 有关详细信息,请参阅将 MinGW 和 Cygwin 与 Visual C++ 和“打开文件夹”结合使用For more information, see Using MinGW and Cygwin with Visual C++ and Open Folder.
  • 添加了支持,以定义 CppProperties.json 和 CMakeSettings.json 中的全局和特定于配置的环境变量。Added support to define global and configuration-specific environment variables in CppProperties.json and CMakeSettings.json. launch.vs.json 中定义的调试配置和 tasks.vs.json 中的任务可以使用这些环境变量。These environment variables can be consumed by debug configurations defined in launch.vs.json and tasks in tasks.vs.json. 有关详细信息,请参阅Customizing your Environment with Visual C++ and Open Folder(使用 Visual C++ 和“打开文件夹”自定义环境)。For more information, see Customizing your Environment with Visual C++ and Open Folder.
  • 改进了对 CMake 的 Ninja 生成器的支持,包括轻松定位 64 位平台的能力。Improved support for CMake's Ninja generator, including the ability to easily target 64-bit platforms.

通过“打开文件夹”支持 CMakeCMake support via Open Folder

Visual Studio 2017 支持在不转换为 MSBuild 项目文件 (.vcxproj) 的情况下使用 CMake 项目。Visual Studio 2017 introduces support for using CMake projects without converting to MSBuild project files (.vcxproj). 有关详细信息,请参阅 Visual Studio 中的 CMake 项目For more information, see CMake projects in Visual Studio. 使用“打开文件夹”打开 CMake 项目会自动配置用于 C++ 编辑、生成和调试的环境。Opening CMake projects with Open Folder automatically configures the environment for C++ editing, building, and debugging.

  • 无需在根文件夹中创建 CppProperties.json 文件,C++ IntelliSense 便可正常工作。C++ IntelliSense works without the need to create a CppProperties.json file in the root folder. 我们还增添了一个新的下拉列表,允许用户在分别由 CMake 和 CppProperties.json 文件提供的配置之间轻松切换。We've also added a new dropdown to allow users to easily switch between configurations provided by CMake and CppProperties.json files.

  • 通过 CMakeLists.txt 文件所在的同一文件夹中的 CMakeSettings.json 文件提供进一步的配置支持。Further configuration is supported via a CMakeSettings.json file that sits in the same folder as the CMakeLists.txt file.

    CMake 项目使用“打开文件夹”CMake Open Folder

Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 添加了对 CMake Ninja 生成器的支持。Support added for the CMake Ninja generator.
Visual Studio 2017 版本 15.4Visual Studio 2017 version 15.4
  • 添加了对导入现有 CMake 缓存的支持。Support added for importing existing CMake caches.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

Windows 桌面开发Windows desktop development

现提供原始 C++ 工作流的更细化的安装体验。We now provide a more granular installation experience for installing the original C++ workload. 我们添加了可选组件,使你能够仅安装所需工具。We have added selectable components that enable you to install just the tools that you need. 在安装程序 UI 中列出的组件的安装大小指示是不正确的,并低估了总大小。The indicated installation sizes for the components listed in the installer UI are incorrect, and underestimate the total size.

若要在 C++ 桌面工作负载中成功创建 Win32 项目,则必须安装工具集和 Windows SDK。To successfully create Win32 projects in the C++ desktop workload, you must install both a toolset and a Windows SDK. 安装推荐(选中)的组件“VC++ 2017 v141 工具集(x86、x64)”和“Windows 10 SDK (10.0.nnnnn)”可以确保正常运行 。Install the recommended (selected) components VC++ 2017 v141 toolset (x86, x64) and Windows 10 SDK (10.0.nnnnn) to make sure it works. 如果没有安装必要的工具,就无法成功创建项目,且向导将停止响应。If the necessary tools aren't installed, projects won't be created successfully, and the wizard will stop responding.

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

Visual C++ 生成工具(以前作为单独的产品提供)现在作为工作负荷包括在 Visual Studio 安装程序中。The Visual C++ Build tools (previously available as a standalone product) are now included as a workload in the Visual Studio Installer. 此工作负荷仅安装生成 C++ 项目所需的工具,而不安装 Visual Studio IDE。This workload installs only the tools required to build C++ projects without installing the Visual Studio IDE. 包括 v140 和 v141 工具集。Both the v140 and v141 toolsets are included. v141 工具集包含 Visual Studio 2017 版本 15.5 中的最近改进。The v141 toolset contains the latest improvements in Visual Studio 2017 version 15.5. 有关详细信息,请参阅 Visual Studio Build Tools now include the VS2017 and VS2015 MSVC Toolsets(Visual Studio 生成工具现在包含 VS2017 和 VS2015 MSVC 工具集)。For more information, see Visual Studio Build Tools now include the VS2017 and VS2015 MSVC Toolsets.

使用 C++ 的 Linux 开发Linux development with C++

热门扩展“用于 Linux 开发的 Visual C++”现已纳入 Visual Studio。The popular extension Visual C++ for Linux Development is now part of Visual Studio. 此安装提供开发和调试运行在 Linux 环境中的 C++ 应用程序所需的一切信息。This installation provides everything you need to develop and debug C++ applications running on a Linux environment.

Visual Studio 2017 版本 15.2Visual Studio 2017 version 15.2

在跨平台代码共享和类型可视化方面进行了改进。Improvements have been made in cross-platform code sharing and type visualization. 有关详细信息,请参阅跨平台代码共享和类型可视化的 Linux C++ 改进For more information, see Linux C++ improvements for cross-platform code sharing and type visualization.

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • Linux 工作负荷添加了对 rsync 作为 sftp 的替代方法将文件同步到远程 Linux 计算机的支持 。The Linux workload has added support for rsync as an alternative to sftp for synchronizing files to remote Linux machines.
  • 添加了对针对 ARM 微控制器的交叉编译的支持。Support is added for cross compilation targeting ARM microcontrollers. 要在安装中启用此支持,请选择使用 C++ 工作负载的 Linux 开发,并选择“嵌入和 IoT 开发”选项 。To enable it in the installation, choose the Linux development with C++ workload and select the option for Embedded and IoT Development. 此选项将 ARM GCC 交叉编译工具和 Make 添加到你的安装。This option adds the ARM GCC cross compilation tools and Make to your installation. 有关详细信息,请参阅 ARM GCC Cross Compilation in Visual Studio(Visual Studio 中的 ARM GCC 交叉编译)。For more information, see ARM GCC Cross Compilation in Visual Studio.
  • 添加了对 CMake 的支持。Support added for CMake. 现在即可处理现有的 CMake 基本代码,无需将其转换为 Visual Studio 项目。You can now work on your existing CMake code base without having to convert it to a Visual Studio project. 有关详细信息,请参阅配置 Linux CMake 项目For more information, see Configure a Linux CMake Project.
  • 添加了对运行远程任务的支持。Support added for running remote tasks. 此功能允许在 Visual Studio 连接管理器定义的远程系统上运行任意命令。This capability allows you to run any command on a remote system that is defined in Visual Studio's Connection Manager. 远程任务还提供将文件复制到远程系统的功能。Remote tasks also provide the capability to copy files to the remote system. 有关详细信息,请参阅配置 Linux CMake 项目For more information, see Configure a Linux CMake Project.
Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

使用 C++ 的游戏开发Game development with C++

以 DirectX 或 Cocos2d 为后盾,利用 C++ 的强大功能构建专业游戏。Use the full power of C++ to build professional games powered by DirectX or Cocos2d.

使用适用于 Android 和 iOS 的 C++ 的移动开发Mobile development with C++ for Android and iOS

现可利用 Visual Studio 创建和调试面向 Android 和 iOS 的移动应用。You can now create and debug mobile apps using Visual Studio that can target Android and iOS.

通用 Windows 应用Universal Windows Apps

C++ 是通用 Windows 应用工作负荷的可选组件。C++ comes as an optional component for the Universal Windows App workload. 目前,必须手动升级 C++ 项目。Currently, you must upgrade C++ projects manually. 可以在 Visual Studio 2017 中打开定目标到 v140 的通用 Windows 平台项目。You can open a v140-targeted Universal Windows Platform project in Visual Studio 2017. 不过,如果没有安装 Visual Studio 2015,则需要在项目属性页中选择 v141 平台工具集。However, you need to select the v141 platform toolset in the project property pages if you don't have Visual Studio 2015 installed.

通用 Windows 平台 (UWP) 上 C++ 的新选项New options for C++ on Universal Windows Platform (UWP)

现可使用新选项编写和打包面向通用 Windows 平台和 Microsoft Store 的 C++ 应用程序:借助桌面桥基础结构,可打包现有的桌面应用程序或 COM 对象,用于通过 Microsoft Store 部署。You now have new options for writing and packaging C++ applications for the Universal Windows Platform and the Windows Store: The Desktop Bridge infrastructure lets you package your existing desktop application or COM object for deployment through the Windows Store. 或者,用于借助旁加载通过现有通道部署。Or, for deployment through your existing channels via side-loading. Windows 10 中的新功能使你能够以各种方式将 UWP 功能添加到桌面应用程序。New capabilities in Windows 10 enable you to add UWP functionality to your desktop application in various ways. 有关详细信息,请参阅桌面桥For more information, see Desktop Bridge.

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

添加了“Windows 应用程序打包项目”项目模板,极大地简化了使用桌面桥打包桌面应用程序的工作。A Windows Application Packaging Project project template is added, which greatly simplifies packaging of desktop applications with Desktop Bridge. 可在“文件 | 新建 | 项目 | 已安装 | Visual C++ | 通用 Windows 平台”下获得此模板。It's available under File | New | Project | Installed | Visual C++ | Universal Windows Platform. 有关详细信息,请参阅使用 Visual Studio(桌面桥)打包应用For more information, see Package an app by using Visual Studio (Desktop Bridge).

在编写新代码时可使用 C ++ / WinRT,它是 Windows 运行时的标准 C ++ 语言投影,仅在头文件中实现。When writing new code, you can now use C++/WinRT, a standard C++ language projection for the Windows Runtime implemented solely in header files. 它可便于使用任何符合标准的 C++ 编译器来使用和创作 Windows 运行时 API。It allows you to consume and author Windows Runtime APIs using any standards-compliant C++ compiler. C++/WinRT 旨在为 C++ 开发人员提供对新式 Windows API 的优先访问权限。C++/WinRT is designed to provide C++ developers with first-class access to the modern Windows API. 有关详细信息,请参阅 C++/WinRTFor more information, see C++/WinRT.

自 Windows SDK Insider Preview 内部版本 17025 起,C++/WinRT 包含在 Windows SDK 中。Starting in build 17025 of the Windows SDK Insider Preview, C++/WinRT is included in the Windows SDK. 有关详细信息,请参阅 C++/WinRT is now included the Windows SDK(C++/WinRT 现在包含在 Windows SDK 中)。For more information, see C++/WinRT is now included the Windows SDK.

Clang/C2 平台工具集The Clang/C2 platform toolset

Visual Studio 2017 随附的 Clang/C2 工具集现在支持 /bigobj 开关,这对生成大项目来说至关重要。The Clang/C2 toolset that ships with Visual Studio 2017 now supports the /bigobj switch, which is crucial for building large projects. 它还在编译器前端和后端进行了多项重要的缺陷修复。It also includes several important bug fixes, both in the compiler front-end and back-end.

C++ 代码分析C++ code analysis

用于强制执行 C++ 核心准则 的 C++ 核心检查器现已通过 Visual Studio 分发。The C++ Core Checkers for enforcing the C++ Core Guidelines are now distributed with Visual Studio. 在项目属性页的“代码分析扩展”页中,启用检查器。Enable the checkers in the Code Analysis Extensions page in the project's property pages. 然后,在运行代码分析时,包括这些扩展。The extensions are then included when you run code analysis. 有关详细信息,请参阅使用 C++ 核心准则检查器For more information, see Using the C++ Core Guidelines checkers.

显示已选中“配置属性”>“代码分析”>“常规”以及“运行此规则集”部分中列出的核心检查数的“属性页”对话框的屏幕截图。Screenshot of the Property Pages dialog box showing Configuration Properties > Code Analysis > General selected and a number of Core Checks listed in teh Run this rule set section.

Visual Studio 2017 版本 15.3Visual Studio 2017 version 15.3
  • 添加了对与资源管理相关的规则的支持。Support added for rules related to resource management.
Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5
  • 新的 C++ Core Guidelines 检查涉及智能指针正确性、全局初始值设定项的正确使用,以及标记构造的使用(如 goto 和错误强制转换)。New C++ Core Guidelines checks cover smart pointer correctness, correct use of global initializers, and flagging uses of constructs like goto and bad casts.

  • 15.3 中可能存在的一些警告编号在 15.5 中不再可用。Some warning numbers you may find in 15.3 are no longer available in 15.5. 这些警告被更具体的检查替换。These warnings were replaced with more specific checks.

Visual Studio 2017 版本 15.6Visual Studio 2017 version 15.6
Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

Visual Studio 2017 中的单元测试Unit testing in Visual Studio 2017

Visual Studio 2017 版本 15.5Visual Studio 2017 version 15.5

Google Test Adapter 和 Boost.Test Adapter 现在作为“使用 C++ 的桌面开发”工作负载的组件提供。Google Test Adapter and Boost.Test Adapter are now available as components of the Desktop Development with C++ workload. 它们与测试资源管理器集成。They're integrated with Test Explorer. 添加了对 CMake 项目(使用“打开文件夹”)的 CTest 支持,尽管与测试资源管理器的完全集成尚不可用。CTest support is added for CMake projects (using Open Folder), although full integration with Test Explorer isn't available yet. 有关详细信息,请参阅编写 C/C++ 单元测试For more information, see Writing unit tests for C/C++.

Visual Studio 2017 版本 15.6Visual Studio 2017 version 15.6
  • 现已开始支持 Boost.Test 动态库。Support added for Boost.Test dynamic library support.
  • IDE 中现提供 Boost.Test 项模板。A Boost.Test item template is now available in the IDE.

有关详细信息,请参阅 Boost.Test 单元测试:动态库支持和新的项模板For more information, see Boost.Test Unit Testing: Dynamic Library support and New Item Template.

Visual Studio 2017 15.7 版Visual Studio 2017 version 15.7

针对 C++ 单元测试项目添加了对 CodeLens 的支持。CodeLens support added for C++ unit test projects. 有关详细信息,请参阅 Announcing CodeLens for C++ Unit Testing(宣布推出用于 C++ 单元测试的 CodeLens)。For more information, see Announcing CodeLens for C++ Unit Testing.

Visual Studio 图形诊断Visual Studio graphics diagnostics

Visual Studio 图形诊断工具:可以使用它们来记录和分析 Direct3D 应用中的呈现和性能问题。Visual Studio Graphics Diagnostics tools: You can use them to record and analyze rendering and performance problems in Direct3D apps. 可以在 Windows 电脑、Windows 设备仿真器或远程电脑/设备上本地运行的应用程序上使用它们。Use them on apps that run locally on your Windows PC, in a Windows device emulator, or on a remote PC or device.

  • 顶点和几何着色的输入和输出: 查看顶点着色器和几何着色器的输入和输出一直以来是最渴求的功能之一。Input & Output for Vertex and Geometry shaders: The ability to view input and output of vertex shaders and geometry shaders has been one of the most requested features. 工具中现已支持此功能。It's now supported in the tools. 在“管道阶段”视图中选择“VS”或“GS”阶段,即可在下面的表中开始检查其输入和输出。Select the VS or GS stage in the Pipeline Stages view to start inspecting its input and output in the table below.

    着色器的输入/输出

  • 在对象表中搜索和筛选: 提供一种快捷简单的方法来查找所需资源。Search and filter in the object table: Provides a quick and easy way to find the resources you're looking for.

    已调用“类型”下拉列表和“搜索”文本框的“对象表”部分的屏幕截图。

  • 资源历史记录: 这种新视图提供了一种简化的方式,以在渲染捕获的帧期间使用资源时查看该资源的整个修改历史记录。Resource History: This new view provides a streamlined way of seeing the entire modification history of a resource as it was used during the rendering of a captured frame. 若要调用任何资源的历史记录,请单击任意资源超链接旁边的时钟图标。To invoke the history for any resource, click the clock icon next to any resource hyperlink.

    资源历史记录

    它显示新的“资源历史记录”工具窗口,其中填充了资源的更改历史记录。It displays the new Resource History tool window, populated with the change history of the resource.

    资源历史记录更改

    可以在启用完整调用堆栈捕获的情况下捕获帧。You can capture frames with full call stack capturing enabled. 这样,可以快速推导每个更改事件的上下文,并在 Visual Studio 项目中检查它。That lets you quickly deduce the context of each change event, and inspect it within your Visual Studio project. 在 Visual Studio 中“工具”>“选项”对话框的“图形诊断”下,设置完整堆栈捕获选项。Set the full stack capture option in the Visual Studio Tools > Options dialog under Graphics Diagnostics.

  • API 统计信息:在帧中查看 API 使用情况的高级摘要。API Statistics: View a high-level summary of API usage in your frame. 这样可以轻松发现你可能根本没有意识到正在执行的调用或执行太频繁的调用。It's handy for discovering calls you may not realize you're making at all, or calls you're making too often. 可在 Visual Studio 图形分析器中通过“视图”>“API 统计信息”使用此窗口。This window is available via View > API Statistics in Visual Studio Graphics Analyzer.

    API 统计信息

  • 内存统计信息: 查看驱动程序为你在帧中所创建的资源分配了多少内存。Memory Statistics: View how much memory the driver allocates for the resources you create in the frame. 可在“Visual Studio 图形分析器”中通过“视图”>“内存统计信息”使用此窗口 。This window is available via View > Memory Statistics in Visual Studio Graphics Analyzer. 若要将数据复制到 CSV 文件以便在电子表格中查看,请右键单击,并选择“全部复制”。To copy data to a CSV file for viewing in a spreadsheet, right-click and choose Copy All.

    内存统计信息

  • 框架验证: 新的错误和警告列表提供了一种简单的方式,以导航到基于潜在问题(由 Direct3D 调试层检测)的事件列表。Frame Validation: The new errors and warnings list provides an easy way to navigate your event list based on potential issues detected by the Direct3D debug layer. 在 Visual Studio 图形分析器中单击“视图”>“帧验证”,可打开该窗口。Click View > Frame Validation in Visual Studio Graphics Analyzer to open the window. 然后单击“运行验证”,开始分析。Then click Run Validation to start the analysis. 这可能耗费数分钟时间,具体取决于帧的复杂性。It can take several minutes to complete, depending on the frame's complexity.

    帧验证

  • 对 D3D12 的帧分析: 使用帧分析来分析具有定向“假设”试验的绘图调用性能。Frame Analysis for D3D12: Use Frame Analysis to analyze draw-call performance with directed "what-if" experiments. 切换至“帧分析”选项卡,然后运行分析以查看报告。Switch to the Frame Analysis tab and run analysis to view the report. 有关详细信息,请观看GoingNative 25:Visual Studio 图形帧分析视频。For more details, watch the GoingNative 25: Visual Studio Graphics Frame Analysis video.

    帧分析

  • GPU 使用情况改进: 使用 GPU 视图或 Windows Performance Analyzer (WPA) 工具,打开通过 Visual Studio GPU 使用情况探查器获取的跟踪,以便获取更详细的分析。GPU Usage Improvements: Open traces can be taken via the Visual Studio GPU Usage profiler with either GPU View or the Windows Performance Analyzer (WPA) tool for more detailed analysis. 如果安装了 Windows Performance Toolkit,则在会话概述的右下方将有两个超链接:一个指向 WPA,另一个指向 GPU 视图。If you have the Windows Performance Toolkit installed, there are two hyperlinks: one for WPA and another for GPU View, at the bottom right of the session overview.

    GPU 使用情况

    通过此链接在 GPU 视图中打开的跟踪支持同步的 VS 和 GPU 视图时间轴缩放和平移。Traces you open in GPU View via this link support synchronized VS and GPU View timeline zooming and panning. VS 中的复选框可控制是否启用同步。A checkbox in VS controls whether synchronization is enabled or not.

    GPU 视图

有关 Visual Studio 2015 Update 3 及之前的版本中新增功能的完整列表,请参阅 Visual C++ 2003 至 2015 中的新增功能For the complete list of what's new through Visual Studio 2015 Update 3, see Visual C++ What's New 2003 through 2015.

若要详细了解 Visual Studio 2015 中的所有新变化,请参阅“发行说明”。For more information on what's new in all of Visual Studio 2015, see the release notes. 它们链接自 Visual Studio 2015 发行说明历史记录They're linked from Visual Studio 2015 Release Notes History.

有关 Visual Studio 2019 中 C++ 新增功能的信息,请参阅 Visual Studio 2019 中 C++ 的新增功能For information on what's new for C++ in Visual Studio 2019, see What's new for C++ in Visual Studio 2019.

有关 Visual Studio 2017 中 C++ 新增功能的信息,请参阅 Visual Studio 2017 中 C++ 的新增功能For information on what's new for C++ in Visual Studio 2017, see What's new for C++ in Visual Studio 2017.