What’s New for C++ Developers in Visual Studio 2022 17.14

Visual Studio 2022 version 17.14 is now generally available! This post summarizes the new features you can find in this release for C++. You can download Visual Studio 2022 from the Visual Studio downloads page or upgrade your existing installation by following the Update Visual Studio Learn page.

Standard Library and Compiler

We’ve made a myriad of fixes and improvements to the MSVC compiler and standard library. See C++ Language Updates in MSVC in Visual Studio 2022 17.14 for a full list of changes on the compiler side, and the STL Changelog for all the standard library updates.

Compiler

We’ve added support for several C++23 features, which are available under the /std:c++latest and /std:c++23preview flags.

You can now omit () in some forms of lambdas that previously required them, thanks to P1102R2:

auto lambda = [] constexpr { }; //no '()' needed after the capture list

We implemented if consteval, with which you can run different code depending on whether the statement is executed at compile time or run time. This is useful for cases where your run time version can be heavily optimized with compiler intrinsics or inline assembly that are not available at compile time:

constexpr size_t strlen(char const* s) {
    if consteval {
        // if executed at compile time, use a constexpr-friendly algorithm
        for (const char *p = s; ; ++p) {
            if (*p == '') {
                return static_cast<std::size_t>(p - s);
            }
        }
    } else {
        // if executed at run time, use inline assembly
        __asm__("SSE 4.2 magic");
    }
}

We now support attributes for lambdas:

auto lambda = [] [[nodiscard]] [[deprecated]] { return 10; };

void f() {
    lambda(); // fires a deprecation warning and a discard of return value warning.
}

We also now support static operator() and static operator[]. These allow the compiler to generate more efficient code for these operators when the implicit object parameter is not needed and therefore does not need to be passed as an argument to the function:

struct X {
    static bool operator()(int) const;
};

inline constexpr X x;

int count_x(std::vector<int> const& xs) {
    return std::count_if(xs.begin(), xs.end(), x);
}

The performance of generated code improved due to 17.14 including earlier SSA optimizations and control-flow simplifications. The 17.14 compiler emits 20% faster code than the initial Visual Studio 2022 17 release.

For throughput, the 17.14 compiler incorporates a dataflow simplification that reduced the compile time of an UnrealEngine /LTCG link repro by 13%.

Standard Library

We have implemented parts of standard library hardening, which checks for some instances of undefined behavior at runtime and reports them to the user. This is currently disabled by default, but you can enable it by defining _MSVC_STL_HARDENING to 1 project-wide. The proposal uses C++26 contract violations as the mechanism for reporting hardened precondition violations, but since we haven’t implemented contracts yet, we default to calling __fastfail().

Another new safety feature we have added is destructor tombstones, which help mitigate use-after-free mistakes. This is also disabled by default, but can be enabled by defining _MSVC_STL_DESTRUCTOR_TOMBSTONES to 1 project-wide.

Some miscellaneous improvements we have made are:

  • We now take advantage of our compiler support for static operator(), which gives slightly improved codegen.
  • We marked std::expected, std::unexpected, and all STL exception types as [[nodiscard]]. This will help protect you from misusing them.
  • Improved the visualizers for std::basic_string_view and its iterators.
  • Added or improved vectorized implementations of std::basic_string::find(), find_first_of(), and find_last_of().

C++ Dynamic Debugging

C++ Dynamic Debugging is a new compiler and IDE feature that gives you the performance of optimized builds with the debugging experience of unoptimized builds. It is now available as a preview feature exclusively with the MSVC toolset and works by dynamically deoptimizing functions that you set deoptimized breakpoints on or step into.

For example, without C++ Dynamic Debugging, you might see this in your Watch window:

Image before

Many of the variables are unavailable, so the debugger cannot visualize them.

When you enable the feature, however, you’ll see this:

Image after

The values of the variables are now available because the function has been dynamically deoptimized.

To begin, change your configuration to Release mode. Next, right-click on your project and click on Properties to open the Configuration Properties menu. In this menu, click on Advanced > Use C++ Dynamic Debugging > Yes. Lastly, rebuild your project. Setting this property will turn off Whole Program Optimization.

screenshot of configuration properties activating C++ dynamic debugging

For all the details about C++ Dynamic Debugging, see our blog post.

IDE

You can now automatically populate template arguments in the template bar, which displays and allows editing of template parameters, when using Go to Definition or F12.

For example, pressing F12 on vector will now jump to vector with the template bar automatically populated, allowing you to quickly inspect and modify template parameters.

In the example below, using Go To Definition or pressing F12 will populate both the type and allocator in the template bar.

Auto Populate Template IntelliSense

We’ve also added support for controlling which headers appear in the include completion list when you type #include.

The dropdown setting in Tools → Options → Text Editor → C/C++ → IntelliSense → Include style for suggestions now affects both include suggestions and include completion, with the following refined behaviors:

  • Core Guidelines (Default): Uses quotes for relative paths and angle brackets for everything else.
  • Quotes mode: Uses quotes for all headers except standard headers, which use angle brackets.
  • Angle brackets mode: Uses angle brackets for all headers that are part of the include path.

Include Style for Suggestions Setting

CMake

We have added support for IntelliSense-based completions and quick info for CMake modules in Visual Studio. Now, you can view all available CMake modules and learn more about them directly from the Visual Studio editor.

Quick Info

When you hover over a referenced CMake module, IntelliSense provides detailed information about the selected module, helping you understand its usage and functionality at a glance.

CMake information in the Quick Info

Completion

When you start typing a CMake module in your CMakeLists.txt or other CMake script files, IntelliSense will provide a list of available modules to choose from.

CMake module completion

GitHub Copilot

We’ve added doc comment generation support for GitHub Copilot. With this feature enabled, you can type the comment pattern according to your settings configuration (e.g., ///), and Copilot will complete the function description based on the code.

AI doc comments

Also new in this release is Next Edit Suggestions (NES). When you’re presented with an edit suggestion, if it is on a different line than the one you are on now, it will suggest you Tab to Navigate to the corresponding line first.

You can enable NES at Tools → Options → GitHub → Copilot → Copilot Completions → Enable Next Edit Suggestions.

NES Tab to Jump Hint Bar

Unreal Engine Blueprints Debugger

The Unreal Engine Blueprint integration allows you to debug Blueprints directly within Visual Studio. This integration includes displaying Blueprint stack traces in the Visual Studio call stack tab and showing Blueprint node values in the local variables table. These features limit the need for you to switch between Visual Studio and the Unreal Editor, providing a seamless debugging experience and reducing context-switching.

Picture 1, Picture

With the new functionality, developers can easily track interactions between Blueprints and C++ code, making it simpler to identify and fix bugs. Additionally, an Unreal Engine plugin for Visual Studio enhances this capability by tracking Blueprint execution flow and storing additional information, which the debugger extension can then display.

Address Sanitizer

We have resolved various issues and feedback tickets, enhancing the quality and stability of Address Sanitizer. We have published a comprehensive list of issues we resolved in Visual Studio 2022 17.13 here and will publish a similar one for 17.14 soon.

To further improve the quality of both Address Sanitizer and our toolchain, we now instrument the entire toolchain with Address Sanitizer on each pull request. Then, internal test pipelines are executed against this instrumented toolset to protect against memory safety errors. This process enables the identification of novel memory safety issues within the toolset and improves the quality of Address Sanitizer through an expedited feedback loop. The Visual C++ Library implementation in the STL GitHub repository is also tested daily using Address Sanitizer using a dedicated pipeline.

Send us your feedback

We are very much interested in your feedback to continue to improve this experience. The comments below are open. Feedback can also be shared through Visual Studio Developer Community. You can also reach us via email at visualcpp@microsoft.com.

The post What’s New for C++ Developers in Visual Studio 2022 17.14 appeared first on C++ Team Blog.

Previous Article

Agent mode has arrived in preview for Visual Studio

Next Article

.NET 10 Preview 4 is now available!

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *