Visual Studio 2019 Preview 2 Improvements

The recently released Preview 2 of Microsoft Visual Studio 2019 contains quite a few improvements and new features.

Lifetime Profile Checker

Preview 2 includes a Lifetime Profile Checker that implements the Lifetime Profile as published by the C++ Core Guidelines. It includes:

  • Support for iterators, string_views, and spans.
  • Better detection of custom Owner and Pointer types which allows custom types that behave like Containers, Owning-Pointers, or Non-Owning Pointers to participate in the analysis.
  • Type-aware default rules for function call pre and post conditions help reduce false-positives and improve accuracy.
  • Better support for aggregate types.
  • General correctness and performance improvements.
  • Some simple nullptr analysis.

This feature is not enabled by default, but you can enable it in the code analysis ruleset for your project. An example of what this checker can catch is the following in which we have a dangling string_view:

std::string get_string();
void dangling_string_view()
{
    std::string_view sv = get_string();
    auto c = sv.at(0);
}

You can read more about this feature here.

Backend Updates: New Optimizations, OpenMP, and Build Throughput improvements

New features include:

  • Added a new inlining command line switch: -Ob3. -Ob3 is a more aggressive version of -Ob2.
  • Added basic support for OpenMP SIMD vectorization.
  • Added a new C++ exception handler __CxxFrameHandler4 that reduces exception handling metadata overhead by 66%.
  • Support for Short Vector Math Library (SVML) intrinsic functions.

New and improved optimizations include:

  • Useless struct/class copies are being removed in several more cases, including copies to output parameters and functions returning an object. This optimization is especially effective in C++ programs that pass objects by value.
  • Unrolled memsets and block initializations will now use SSE2 instructions (or AVX instructions if allowed).
  • The compiler recognizes memmove() as an intrinsic function and optimizes accordingly.
  • Several new scalar fused multiply-add (FMA) patterns are identified with /arch:AVX2 /fp:fast.

Preview 2 also improves build throughput. Link times might be improved up to 2x.

The new linker will now report potentially matched symbol(s) for unresolved symbols, like:

main.obj : error LNK2019: unresolved external symbol _foo referenced in function _main
  Hint on symbols that are defined and could potentially match:
    "int __cdecl foo(int)" (?foo@@YAHH@Z)
    "bool __cdecl foo(double)" (?foo@@YA_NN@Z)
    @foo@0
    foo@@4
main.exe : fatal error LNK1120: 1 unresolved externals

More details can be found on this blog post.

Template IntelliSense Improvements

The following updates for Template IntelliSense are included with Preview 2:

  • Peek Window UI
  • Live Edits
  • Nested Template support
  • Default Argument watermarks

Read all about it on this blog post.

C++ Productivity Improvements

Preview 2 comes with the following new quick fixes and code navigation improvements:

  • Quick fixes for:
    • Add missing #include
    • NULL to nullptr
    • Add missing semicolon
    • Resolve missing namespace or scope
    • Replace bad indirection operands (* to & and & to *)
  • Quick Info on closing brace
  • Peek Header / Code File
  • Go to Document on #include

Read more about this new features here.

New Code Analysis Checks

Preview 2 includes new code analysis checks:

  • Use-after-move checker
  • Coroutine related checkers

Read more about them here.

In-editor Code Analysis Improvements

Code analysis now runs automatically in the background, and warnings display as green squiggles in-editor. Analysis re-runs every time you open a file in the editor and when you save your changes.

Squiggles are improved. Squiggles are now only displayed underneath the code segment that is relevant to the warning.

Read more here.

Share

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: