C++ Language Updates in MSVC in Visual Studio 2022 17.14

Introduction

In this update, we continue the tradition of bucketing bugs into helpful categories for you all to filter through along with even more notes from the compiler team as to what, exactly, was fixed. This blog is also complemented by the recent Pure Virtual C++ pre-conference talk by RanDair Porter; so please check out RanDair’s talk, “MSVC C++23 Conformance”, if you have not already to get a better view of MSVC’s conformance status for Visual Studio 2022 overall.

17.13 notes for reference.

C++23 Features

Note: C++23 features can be used by either adding /std:c++latest or
/std:c++23preview to the command line. In addition, features used from unfinished standards may not
have full IntelliSense support.

  • Add support for P1102R2
    (Down with ()!) which makes a parameter-list an optional part of a lambda-declarator.
auto lambda = [] constexpr { }; // C++23: can now omit the '()' after the capture list.
  • Implemented P1938R3:
    if consteval for C++23.
constexpr int f(int) {
  if consteval { // C++23: previously this would be 'if (std::is_constant_evaluated()) { ... }'.
    return 42;
  }
  else {
    return 1337;
  }
}
int main(int argc, const char**) {
  static_assert(f() == 42);
  int x = f(argc);
  if (x != 1337) // Since 'f' cannot be evaluated at compile-time, the value here is '1337'
                 // due to taking the 'else' branch in 'f'.
    return 1;
}
  • Implement P1401R5
    Narrowing contextual conversions to bool, making the following well-formed as of C++23:
enum Flags { Zero, One, Two };
static_assert(One | Two);
  • Add support of P2173R1
    attributes for lambda-expressions.
auto lambda = [] [[nodiscard]] [[deprecated]] { return 10; };
void f() {
  lambda(); // C++23: Attributes here will fire a deprecation warning and a discard of return value warning.
}
  • Implement P1169R4 which adds
    support for static operator().
  • Implement P2589R1 which adds
    support for static operator[].
struct Functor {
  static constexpr int operator()() { return 42; }
  static constexpr int operator[](int) { return 42; }
};
using T1 = decltype(Functor::operator()());  // C++23: Deduces to 'int'.
static_assert(Functor::operator()() == 42); // C++23: Can be used without creating a 'Functor' object.

using T2 = decltype(Functor::operator[](10));  // C++23: Deduces to 'int'.
static_assert(Functor::operator[](10) == 42); // C++23: Can be used without creating a 'Functor' object.

Smaller C++23 Items

  • Implement CWG2428 – Deprecating a concept.

Compiler improvements for 17.14

C++/CLI

Diagnostics

constexpr

C++ Modules

Conformance

Reliability

Correctness

Correctness (C compiler)

The post C++ Language Updates in MSVC in Visual Studio 2022 17.14 appeared first on C++ Team Blog.

Previous Article

Q&A: A roadmap for revolutionizing health care through data-driven innovation

Next Article

Hybrid AI model crafts smooth, high-quality videos in seconds

Write a Comment

Leave a Comment

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