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.
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 forstatic operator()
. - Implement P2589R1 which adds
support forstatic 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
- Fix bug where std::optional could not be used with managed types.
- Fix an issue related to nested lambdas and pack-expansions and stop emitting a warning related to
‘volatile’ if the class type is imported. - Fix regression in C++/CLI which causes a crash or bad diagnostics when calling functions with parameter-arrays
and compiling for Net Core. - Compilation
Error Occurs When Using std::shared_ptr in C++/CLI Code
Diagnostics
- Add a warning to detect undefined behavior mentioned in [meta.reqmts].
- Fixes the lack of a diagnostic on an initialization getting skipped over in a switch statement.
- Fix missing error diagnostic for explicit constructor initialization
constexpr
- Prevent binding constexpr references to local temporaries
- Fix spurious error where
if consteval
would not properly be considered in consetxpr functions. - Fix an issue with combing a non-type template parameter of reference type with a template argument that is a
function call that returns by reference. - Fix a bug in immediate function folding that resulted in bad string data
- Fix incorrect C7595 errors in constructor member initializers and as the object expression of member access
expressions - We now run destructors during constant evaluation that appear in the init-stmt of a for loop
- Fixed constexpr __builtin_memcmp comparing unsigned chars
- Fix an incorrect rejection of an out-of-line static constexpr data member definition
- Assigning
value to field of base class in constexpr virtual function gennerates ICE - Labeled
statements is incorrectly rejected during constant evaluation
C++ Modules
- Fix issue where the compiler would sometimes issue a syntax error when parsing template-ids from a module.
- Fixed an issue where users would sometimes see linker errors with certain inline functions from a module and
various other compiler issues when building with header units enabled for Unreal Engine 5. - Fix ICE in the compiler when importing a type with an apparent cyclic dependency on itself
- Fixed an issue where custom-defined data sections were not persisted into a C++ module.
- Fixed a case where C5260 was firing spuriously
- Fixed an issue where using a class marked as
__declspec(dllimport)
would sometimes issue a linker
error when imported through a module. - Fixed an issue where the compiler would sometimes crash when loading a PCH with a module import.
- Fixed a bug where functions returning
auto
would sometimes not be resolved from a module. - Fixed compiler crash in modules when using lambdas in static member functions of a class.
- Fix a compiler crash when trying to match explicit object member functions which originate outside a C++ module.
- Fix an issue with mdspan and modules.
- Fixed an issue when using
std::ranges
in modules where the compiler would issue a syntax error. - Fix issue where
__vectorcall
functions in a module would sometimes not compile.
Conformance
- Implement CWG 1213: Array subscripting and xvalues
- Added
/Zc:u8EscapeEncoding
for conformant encoding of escape sequences like u8″xFF” - Fix missing diagnostic for mixing ‘friend’ and ‘static’.
- Fix issue where lookup-related diagnostics are missing in fold expressions
- Fixed an issue where the compiler did not conform to P1779R3.
Reliability
- Fix a compiler crash when using d1initall and constant evaluation
- Fix a compiler crash caused by a pointer-to-member
- Fix a silent compiler crash on certain malformed explicit destructor calls.
- Fix a compiler crash related to default function parameters
- Fix an issue with name-lookup of a conversion-function-id and an issue related to the pack-expansion of
a nested lambda. - Fix an ICE in certain alias template definitions with multi-component, dependent nested names.
- Fix ICE when C11 _Atomic is used with PCH
- Fix an ICE with certain noexcept-specifiers
- Fix a crash in constant evaluation with base-to-derived conversions of pointers to array elements
- Fix an issue relating to explicit lambda template parameters and also an issue related to a multidimensional
subscript operator - Fixes extreme memory use for some zero-initialized arrays (and aggregates thereof)
- Fix an ICE on a decltype containing a noexcept expression
- Fix an issue with class template argument deduction for alias templates
- Fix an ICE with some ill-formed qualified names.
- Fix an issue with dependent base-classes and class template argument deduction for aggregates.
- Fix a crash with brace-initialization of an object containing a const reference member
- fatal
error C1001: Internal compiler error on atomic operation with struct
Correctness
- Fix incorrect error given when a base class name referenced in a template is found on multiple base class paths.
- Correct an issue with using directives not being respected in some nested lambdas.
- Add missing diagnostic for ill-formed pure-specifier and fix issue with combination of ‘volatile’ and
copy-assignment operators. - Fix an issue related to the backing array for a std::initializer_list being destroyed too soon.
- Fix an issue with lambda captures within a decltype-specifier, and an issue with a static_assert within a
concept. - Fix a case where the compiler dropped pointer dereference of a cast of a pointer to an array in some cases
- Fix incorrect access checks in certain alias templates
- Fix an issue where a volatile reference could bind to an rvalue of a derived class
- Fix an issue with the initialization of a variable of class type that is volatile.
- Fix incorrect error C3770 when certain alias template specializations are used as base classes
- Fix an issue with capturing ‘this’ in a lambda that is part of an init-capture and an issue in which the
compiler to did not correctly handle an abstract class type during template argument substitution. - Fix an issue in which a variable with an ‘auto’ type was referenced before its type had been deduced and
an issue in which a valid goto-statement within an if-constexpr statement was flagged as an error. - Fix an issue in which warning C4100, “unused parameter”, was not emitted,
- Fix an invalid error C2210 with some alias template specializations
- Fix an issue with lambdas in a class with virtual bases.
- Fix an issue with the zero-initialization of arrays with /d1initAll
- Fix an issue with decltype and calls to static member functions with an object and an issue with warnings and
the conditional operator - Address an issue in which C4100, unused parameter, was not emitted.
- Fix an issue with aggregate initialization when a non-static data member is a self-referential reference type.
- Fix an issue with hidden friend functions that are declared to return ‘auto’
- Fix a regression that a deduction guide has incorrect return type.
- Correct invalid implicit move of extern or thread_local variables
- Fix issue where braced initialization in a non-type template argument would confuse the compiler.
- Fix an issue with a template-id that had a template-argument that used a decltype-specifier and fix an issue
with a variable template + class template argument deduction + lambdas - Fix an issue with ‘[[no_unique_address]]’ and trivial copy/move assignment operators.
- Fix and issue with a compiler requires-expression in an if-constexpr statement.
- Fix incorrect template specialization involving certain qualified-names and dependent base classes.
- Fix incorrect access checks in certain alias templates
- Fix an incorrect type-deduction failure involving certain template specializations and empty packs.
- Fixed a bug where a user-provided
operator,
would sometimes not be called if there was a cast
involved on one of the operands. - Fix an issue with undecorating cv-qualified nullptr.
- Reduced implementation divergence between clang and gcc when C++23 explicit object functions are called in
various cases. - Fix an issue related to pack-expansion and an issue related to the use of ‘decltype(auto)’ within a
lambda. - Fix an issue causing temporaries to be required in certain conditional expressions.
- Add missing checks for deduction guide and trailing return type.
- Fix an issue with the compiler emitting the IL for a special member function when it was not ODR used.
- C++20
compile error with ATL::CComPtr<> - Cannot
capture local constexpr closure object in lambda in C++20 mode - VisualCppTools
/ ppltasks.h race condition bug in when_any - Write
to base class member through virtual function called by another function fails to compile. - vcruntime
nothrow array operator new falls back on the wrong function - 17.12.5
internal preview fails to scan PreFast on cppcorecheck plugin - MSVC
instantiates constexpr destructors too early when data member initializers are involved - VC++ 2017:
Member enumeration of class template cannot be defined outside of the class template definition. - MSVC
19.43.34808 Preprocessor Bug:/EP
Adds Unwanted#pragma warning
Directives
(Introduced in VS 2022 v17.13.x, Corrupts Preprocessed Files) - Requires
clause rejected in lambda initializing a variable template - False
positive lifetime code analysis warning C26849: Don’t dereference an invalid pointer: (lifetime.1). - C26822
false positive with not_null - can’t compile
with valid CTAD - Type
always prefered over value when using qualified identifiers - std::bit_cast
does not work for bit-fields equal to whole type - Bit
fields with widths computed via template are treated as 1-bit fields instead starting with MSVC 19.40 - OpenJDK
(jdk17u) build failure with VS2022: error C2244: ‘TestEnableIfNested::sub1’: unable to match
function definition to an existing declaration - C26815
false positive on “return *this;” with assignment of std::optional member in member function. - Trivial
template argument expressions broken in 14.44 - False
positive lifetime code analysis warning C26847: Don’t return an invalid pointer (lifetime.4). - Inconsistent
ESP analysis defects after 17.10 update (Office) - Breakpoint
line mismatch due to VC++ compiler parse the line number wrongly, when a template class with alignas and
comma - Microsoft
cl compiler successfully compile code that has unnecessary template-id specified.
Correctness (C compiler)
- C Make char types unique for
_Generic
operator - C dropped pointer dereference of a cast of a pointer to an array in some cases
- C compiler stack overflow on large array initialization
The post C++ Language Updates in MSVC in Visual Studio 2022 17.14 appeared first on C++ Team Blog.