Skip to content

Commit ecb8263

Browse files
committed
draft
1 parent 2a6681a commit ecb8263

File tree

2 files changed

+89
-8
lines changed

2 files changed

+89
-8
lines changed

docs/overview/msvc-conformance-improvements.md

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,51 @@ struct S
8888

8989
This change allows you to use the explicit object parameter syntax (deducing `this`) in assignment and comparison operators, providing more consistent syntax across different types of member functions.
9090

91+
92+
### P2266R1 : Simpler implicit move
93+
94+
The introduction of [P2266R1](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html) may cause code that was previously treated as an lvalue to be treated as an xvalue or a prvalue. For example:
95+
96+
```cpp
97+
#include <utility>
98+
99+
template<typename T>
100+
T& f(T&& t)
101+
{
102+
return t;
103+
}
104+
105+
struct S { };
106+
107+
void g()
108+
{
109+
S s1{ };
110+
S& s2 = f(std::move(s1));
111+
}
112+
```
113+
114+
In C++20, and earlier, this code would have compiled because even though the type of `t` is `S&&` the use of `t` in `return t` is treated as a glvalue and so it can bind to the return type.
115+
116+
With C++23, `t` is treated as an xvalue and so it can't bind to an lvalue reference.
117+
118+
One fix is to change to the return type of the function from `T&` to `T&&` but this may affect code that calls this function. An alternative is to use the feature test macro that is associated with this change. For example:
119+
120+
```cpp
121+
#include <type_traits>
122+
123+
template<typename T>
124+
T& f(T&& t)
125+
{
126+
#if defined(__cpp_implicit_move)
127+
return static_cast<std::remove_reference_t<T>&>(t);
128+
#else
129+
return t;
130+
#endif
131+
}
132+
```
133+
134+
Adding the cast means that the value-category of the return expression is now an lvalue and so it can bind to the return type.
135+
91136
### P2280R4: References to unknown values during constant evaluation
92137

93138
[P2280R4](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2280r4.html) allows references to unknown values during constant evaluation, relaxing restrictions on `constexpr` evaluation.
@@ -126,29 +171,61 @@ MSVC Build Tools v14.50 includes numerous smaller conformance improvements that
126171
127172
For more information about compiler improvements and bug fixes in MSVC Build Tools v14.50, see [C++ Language Updates in MSVC Build Tools v14.50](https://devblogs.microsoft.com/cppblog/c-language-updates-in-msvc-build-tools-v14-50/)
128173
129-
### Conformance Enhancements
174+
## Conformance Enhancements
130175
131176
Improved adherence to C++ standards:
132177
133-
#### Attribute Support
178+
### Attribute Support
179+
134180
- Added support for [`[[maybe_unused]]` on labels](https://developercommunity.visualstudio.com/t/unreferenced-label-when-ref-hidden-by-if/102076).
135181
- Fixed warning C4102 (unreferenced label) when the only reference was from a discarded `if constexpr` branch.
136182
137-
#### Template and Specialization Fixes
183+
### Template and Specialization Fixes
184+
138185
- [Diagnosed ill-formed friend explicit specializations](https://developercommunity.visualstudio.com/t/Defining-explicit-function-template-spec/10933841) that were incorrectly accepted in C++20 or later.
139186
- Added `/Zc:enumEncoding` switch to [correctly encode enum non-type template parameters](https://developercommunity.visualstudio.com/t/Overload-resolution-fails-for-enum-non-t/10398088).
140187
- Fixed issues with [missing 'template' keyword diagnostics](https://developercommunity.visualstudio.com/t/No-diagnostic-for-missing-template-in-d/10501221)
141188
142-
#### C++20 and C++23 Features
189+
### C++20 and C++23 Features
143190
144191
- Enhanced [multidimensional operator[] support](https://developercommunity.visualstudio.com/t/Multidimensional-operator-with-Wall-r/10876026)
145192
- Improved [concept and constraint evaluation](https://developercommunity.visualstudio.com/t/VS-1714-if-constexpr-requires--does/10905731)
146193
147194
## Bug fixes
148195
149-
Bug fixes for C++ Modules, `constexpr`, and others were made in v14.50. For a detailed list of bug fixes, see [Compiler Improvements in v14.50](https://devblogs.microsoft.com/cppblog/c-language-updates-in-msvc-build-tools-v14-50/#compiler-improvements-in-v14.50)
196+
Bug fixes for C++ Modules, `constexpr`, and other fixes were made in v14.50. For a detailed list of bug fixes, see [Compiler Improvements in v14.50](https://devblogs.microsoft.com/cppblog/c-language-updates-in-msvc-build-tools-v14-50/#compiler-improvements-in-v14.50)
197+
198+
**Encoding of certain non-type template arguments corrected**
199+
200+
Affects `/stdc++20` or later.
201+
202+
Certain non-type pointer type template arguments involving sub-objects could lead to linking issues or in some cases silent bad code generation where what should be distinct specializations collide.
203+
204+
```cpp
205+
struct A
206+
{
207+
int x;
208+
};
209+
210+
struct B
211+
{
212+
int y;
213+
};
214+
215+
template <auto p> void f();
216+
217+
int main()
218+
{
219+
static A a;
220+
static B b;
221+
constexpr auto px = &a.x;
222+
constexpr auto py = &b.y;
223+
f<px>(); // incorrect encoding of argument 'px'
224+
f<py>(); // incorrect encoding of argument 'py', collided with 'px'.
225+
}
226+
```
150227

151-
https://devblogs.microsoft.com/cppblog/c-language-updates-in-msvc-build-tools-v14-50/#constexpr
228+
With this fix, the two calls to `f` get distinct encodings, as required.
152229

153230
## Migrating to MSVC Build Tools v14.50
154231

docs/overview/visual-cpp-language-conformance.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Microsoft C/C++ language conformance"
33
description: "Microsoft C and C++ conformance updates by Visual Studio version."
4-
ms.date: 10/31/2025
4+
ms.date: 11/03/2025
55
ms.service: "visual-cpp"
66
ms.subservice: "cpp-lang"
77
---
@@ -197,6 +197,7 @@ For details on conformance improvements, see [C++ conformance improvements in Vi
197197
| &emsp;[`P2173R1 Attributes on Lambda-Expressions`](https://wg21.link/p2173r1) | no |
198198
| &emsp;[`P2186R2 Remove Garbage Collection Support`](https://wg21.link/p2186r2) | VS 2022 17.0 <sup>[23](#note_23)</sup> |
199199
| &emsp;[`P2201R1 Mixed string literal concatenation`](https://wg21.link/p2201r1) | no |
200+
| &emsp;[`P2266R1 Simpler implicit move`](https://wg21.link/p2266r1) | VS 2026 18.0 <sup>[24](#note_24)</sup> |
200201
| &emsp;[`P2223R2 Trimming whitespaces before line splicing`](https://wg21.link/p2223r2) | no |
201202
| &emsp;[`P2242R3 Non-literal variables (and labels and gotos) in constexpr functions`](https://wg21.link/p2242r3) | no |
202203
| &emsp;[`P2246R1 Character encoding of diagnostic text`](https://wg21.link/p2246r1) | VS 2022 17.0 <sup>[23](#note_23)</sup> |
@@ -575,7 +576,8 @@ A group of papers listed together indicates a Standard feature along with one or
575576
**VS 2022 17.2** Supported in Visual Studio 2022 version 17.2.\
576577
**VS 2022 17.3** Supported in Visual Studio 2022 version 17.3.\
577578
**VS 2022 17.4** Supported in Visual Studio 2022 version 17.4.\
578-
**VS 2022 17.5** Supported in Visual Studio 2022 version 17.5.
579+
**VS 2022 17.5** Supported in Visual Studio 2022 version 17.5.\
580+
**VS 2022 18** Supported in Visual Studio 2026 and beyond.
579581

580582
### Notes
581583

@@ -646,6 +648,8 @@ These algorithms aren't presently parallelized:
646648

647649
<a name="note_23"></a> **23** In Visual Studio 2022 version 17.0 and up, these features are enabled by the [`/std:c++latest`](../build/reference/std-specify-language-standard-version.md) compiler option.
648650

651+
<a name="note_24"></a> **24** In Visual Studio 2026 version 18.0 and up, these features are enabled by the [`/std:c++latest`](../build/reference/std-specify-language-standard-version.md) compiler option.
652+
649653
<a name="note_C11"></a> **C11** Compiler support for C11 and C17 requires Visual Studio 2019 version 16.8 or higher. Except as noted, C11 and C17 library support requires Windows SDK build 10.0.20211.0 or higher. For more information on how to install support for C11 and C17, see [Install C11 and C17 support in Visual Studio](./install-c17-support.md).
650654

651655
<a name="note_DR"></a> **DR** These features are enabled in all C++ [`/std`](../build/reference/std-specify-language-standard-version.md) compiler option modes. The C++ Standard committee adopted this change as a retroactive Defect Report to C++11 and all later versions.

0 commit comments

Comments
 (0)