You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Microsoft C++ in Visual Studio is progressing toward full conformance with the C++20 language standard."
5
5
ms.technology: "cpp-language"
6
6
author: "mikeblome"
@@ -12,7 +12,7 @@ Microsoft C++ makes conformance improvements and bug fixes in every release. Thi
12
12
13
13
::: moniker range="vs-2019"
14
14
15
-
## <aname="improvements_160"></a> Improvements in Visual Studio 2019 RTW (version 16.0)
15
+
## <aname="improvements_160"></a> Conformance improvements in Visual Studio 2019 RTW (version 16.0)
16
16
17
17
Visual Studio 2019 RTW contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C++ compiler (MSVC)
18
18
@@ -156,7 +156,7 @@ Implemented the `remove_cvref` and `remove_cvref_t` type traits from [P0550](htt
156
156
157
157
[C++20 P1008R1 - prohibiting aggregates with user-declared constructors](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf) is complete.
158
158
159
-
## <aname="improvements_161"></a> Improvements in Visual Studio 2019 version 16.1
159
+
## <aname="improvements_161"></a> Conformance improvements in 16.1
160
160
161
161
### char8_t
162
162
@@ -236,7 +236,7 @@ void f() {
236
236
-`shift_left()` and `shift_right()` added to \<algorithm>.
237
237
238
238
239
-
## <aname="improvements_162"></a> Improvements in Visual Studio 2019 version 16.2
239
+
## <aname="improvements_162"></a> Conformance improvements in 16.2
240
240
241
241
### noexcept constexpr functions
242
242
@@ -246,7 +246,7 @@ Constexpr functions are no longer considered `noexcept` by default when used in
246
246
constexprintf() { return 0; }
247
247
248
248
int main() {
249
-
static_assert(noexcept(f(true)), "f should be noexcept"); // C2338 in 16.2
249
+
static_assert(noexcept(f()), "f should be noexcept"); // C2338 in 16.2
250
250
}
251
251
```
252
252
@@ -256,7 +256,118 @@ To fix the error, add the `noexcept` expression to the function declaration:
256
256
constexprintf() noexcept { return 0; }
257
257
258
258
int main() {
259
-
static_assert(noexcept(f(true)), "f should be noexcept");
259
+
static_assert(noexcept(f()), "f should be noexcept");
260
+
}
261
+
```
262
+
263
+
### Binary expressions with different enum types
264
+
265
+
The ability to apply the usual arithmetic conversions on operands where one is of enumeration type and the other is of a different enumeration type or a floating-point type is deprecated in C++20 ([P1120R0](http://wg21.link/p1120r0)). In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 warning when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
266
+
267
+
```cpp
268
+
enumE1 { a };
269
+
enum E2 { b };
270
+
int main() {
271
+
int i = a | b; // warning C5054: operator '|': deprecated between enumerations of different types
272
+
}
273
+
```
274
+
275
+
To avoid the warning, use [static_cast](../cpp/static-cast-operator.md) to convert the second operand:
276
+
277
+
```cpp
278
+
enumE1 { a };
279
+
enum E2 { b };
280
+
int main() {
281
+
int i = a | static_cast<int>(b);
282
+
}
283
+
```
284
+
285
+
### Binary expressions with enumeration and floating point types
286
+
287
+
The ability to apply the usual arithmetic conversions on operands where one is of enumeration type and the other is of a different enumeration type or a floating-point type is deprecated in C++20 ([P1120R0](http://wg21.link/p1120r0)). In other words, using a binary operation between an enumeration and a floating-point type is now a warning when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
288
+
289
+
```cpp
290
+
enumE1 { a };
291
+
int main() {
292
+
double i = a * 1.1;
293
+
}
294
+
```
295
+
296
+
To avoid the warning, use [static_cast](../cpp/static-cast-operator.md) to convert the second operand:
297
+
298
+
```cpp
299
+
enumE1 { a };
300
+
int main() {
301
+
double i = static_cast<int>(a) * 1.1;
302
+
}
303
+
```
304
+
305
+
### Equality and relational comparisons of arrays
306
+
307
+
Equality and relational comparisons between two operands of array type are deprecated in C++20 ([P1120R0](http://wg21.link/p1120r0)). In other words, a comparison operation between two arrays (regardless of rank and extent similarities) is a now a warning. Starting in Visual Studio 2019 version 16.2, the following code produces *C5056: operator '==': deprecated for array types* when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
308
+
309
+
```cpp
310
+
intmain() {
311
+
int a[] = { 1, 2, 3 };
312
+
int b[] = { 1, 2, 3 };
313
+
if (a == b) { return 1; }
314
+
}
315
+
```
316
+
317
+
To avoid the warning, you can compare the addresses of the first elements:
318
+
319
+
```cpp
320
+
intmain() {
321
+
int a[] = { 1, 2, 3 };
322
+
int b[] = { 1, 2, 3 };
323
+
if (&a[0] == &b[0]) { return 1; }
324
+
}
325
+
```
326
+
327
+
To determine whether the contents of two arrays are equal, use the [std::equal](../standard-library/algorithm-functions.md#equal) function:
### Effect of defining spaceship operator on == and !=
334
+
335
+
A definition of the spaceship operator (**<=>**) alone will no longer rewrite expressions involving **==** or **!=** unless the spaceship operator is marked as `= default` ([P1185R2](https://wg21.link/p1185r2)). The following example compiles in Visual Studio 2019 RTW and version 16.1, but produces C2678 in Visual Studio 2019 version 16.2:
336
+
337
+
```cpp
338
+
#include <compare>
339
+
340
+
struct S {
341
+
int a;
342
+
auto operator<=>(const S& rhs) const {
343
+
return a <=> rhs.a;
344
+
}
345
+
};
346
+
bool eq(const S& lhs, const S& rhs) {
347
+
return lhs == rhs;
348
+
}
349
+
bool neq(const S& lhs, const S& rhs) {
350
+
return lhs != rhs;
351
+
}
352
+
```
353
+
354
+
To avoid the error, define the operator== or declare it as defaulted:
355
+
356
+
```cpp
357
+
#include<compare>
358
+
359
+
structS {
360
+
int a;
361
+
auto operator<=>(const S& rhs) const {
362
+
return a <=> rhs.a;
363
+
}
364
+
bool operator==(const S&) const = default;
365
+
};
366
+
bool eq(const S& lhs, const S& rhs) {
367
+
return lhs == rhs;
368
+
}
369
+
bool neq(const S& lhs, const S& rhs) {
370
+
return lhs != rhs;
260
371
}
261
372
```
262
373
@@ -551,7 +662,7 @@ Fixed a regression in `std::pair`'s assignment operator introduced when implemen
551
662
552
663
Fixed a minor type traits bug, where `add_const_t` and related functions are supposed to be a non-deduced context. In other words, `add_const_t` should be an alias for `typename add_const<T>::type`, not `const T`.
553
664
554
-
## <a name="update_162"></a> Bug fixes and behavior changes in Visual Studio 2019 version 16.2
665
+
## <a name="update_162"></a> Bug fixes and behavior changes in 16.2
555
666
556
667
### Const comparators for associative containers
557
668
@@ -601,122 +712,11 @@ struct Comparer {
601
712
602
713
```
603
714
604
-
### Binary expressions with different enum types
605
-
606
-
The ability to apply the usual arithmetic conversions on operands where one is of enumeration type and the other is of a different enumeration type or a floating-point type is deprecated. In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 warning when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
607
-
608
-
```cpp
609
-
enum E1 { a };
610
-
enum E2 { b };
611
-
int main() {
612
-
int i = a | b; // warning C5054: operator '|': deprecated between enumerations of different types
613
-
}
614
-
```
615
-
616
-
To avoid the warning, use [static_cast](../cpp/static-cast-operator.md) to convert the second operand:
617
-
618
-
```cpp
619
-
enumE1 { a };
620
-
enum E2 { b };
621
-
int main() {
622
-
int i = a | static_cast<int>(b);
623
-
}
624
-
```
625
-
626
-
### Binary expressions with enumeration and floating point types
627
-
628
-
The ability to apply the usual arithmetic conversions on operands where one is of enumeration type and the other is of a different enumeration type or a floating-point type is deprecated. In other words, using a binary operation between an enumeration and a floating-point type is now a warning when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
629
-
630
-
```cpp
631
-
enumE1 { a };
632
-
int main() {
633
-
double i = a * 1.1;
634
-
}
635
-
```
636
-
637
-
To avoid the warning, use [static_cast](../cpp/static-cast-operator.md) to convert the second operand:
638
-
639
-
```cpp
640
-
enumE1 { a };
641
-
int main() {
642
-
double i = static_cast<int>(a) * 1.1;
643
-
}
644
-
```
645
-
646
-
### Equality and relational comparisons of arrays
647
-
648
-
Equality and relational comparisons between two operands of array type are deprecated. In other words, a comparison operation between two arrays (regardless of rank and extent similarities) is a now a warning. Starting in Visual Studio 2019 version 16.2, the following code produces *C5056: operator '==': deprecated for array types* when the [/std:c++latest](../build/reference/std-specify-language-standard-version.md) compiler option is enabled:
649
-
650
-
```cpp
651
-
intmain() {
652
-
int a[] = { 1, 2, 3 };
653
-
int b[] = { 1, 2, 3 };
654
-
if (a == b) { return 1; }
655
-
}
656
-
```
657
-
658
-
To avoid the warning, you can compare the addresses of the first elements:
659
-
660
-
```cpp
661
-
intmain() {
662
-
int a[] = { 1, 2, 3 };
663
-
int b[] = { 1, 2, 3 };
664
-
if (&a[0] == &b[0]) { return 1; }
665
-
}
666
-
```
667
-
668
-
To determine whether the contents of two arrays are equal, use the [std::equal](../standard-library/algorithm-functions.md#equal) function:
### Effect of defining spaceship operator on == and !=
675
-
676
-
A definition of the spaceship operator (**<=>**) alone will no longer rewrite expressions involving **==** or **!=** unless the spaceship operator is marked as `= default`. The following example compiles in Visual Studio 2019 RTW and version 16.1, but produces C2678 in Visual Studio 2019 version 16.2:
677
-
678
-
```cpp
679
-
#include <compare>
680
-
681
-
struct S {
682
-
int a;
683
-
auto operator<=>(const S& rhs) const {
684
-
return a <=> rhs.a;
685
-
}
686
-
};
687
-
bool eq(const S& lhs, const S& rhs) {
688
-
return lhs == rhs;
689
-
}
690
-
bool neq(const S& lhs, const S& rhs) {
691
-
return lhs != rhs;
692
-
}
693
-
```
694
-
695
-
To avoid the error, define the operator== or declare it as defaulted:
696
-
697
-
```cpp
698
-
#include<compare>
699
-
700
-
structS {
701
-
int a;
702
-
auto operator<=>(const S& rhs) const {
703
-
return a <=> rhs.a;
704
-
}
705
-
bool operator==(const S&) const = default;
706
-
};
707
-
bool eq(const S& lhs, const S& rhs) {
708
-
return lhs == rhs;
709
-
}
710
-
bool neq(const S& lhs, const S& rhs) {
711
-
return lhs != rhs;
712
-
}
713
-
```
714
-
715
715
::: moniker-end
716
716
717
717
::: moniker range="vs-2017"
718
718
719
-
## <a name="improvements_150"></a> Improvements in Visual Studio 2017 RTW (version 15.0)
719
+
## <a name="improvements_150"></a> Conformance improvements in Visual Studio 2017 RTW (version 15.0)
720
720
721
721
With support for generalized `constexpr` and non-static data member initialization (NSDMI) for aggregates, the Microsoft C++ compiler in Visual Studio 2017 is now complete for features added in the C++14 standard. However, the compiler still lacks a few features from the C++11 and C++98 standards. See [Visual C++ Language Conformance](../visual-cpp-language-conformance.md) for a table that shows the current state of the compiler.
722
722
@@ -744,7 +744,7 @@ In **/std:c++17** mode, the `[[fallthrough]]` attribute can be used in the conte
744
744
745
745
Range-based for loops no longer require that `begin()` and `end()` return objects of the same type. This change enables `end()` to return a sentinel as used by ranges in [range-v3](https://github.com/ericniebler/range-v3) and the completed-but-not-quite-published Ranges Technical Specification. For more information, see [Generalizing the Range-Based For Loop](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0184r0.html).
746
746
747
-
## <a name="improvements_153"></a> Improvements in Visual Studio 2017 version 15.3
747
+
## <a name="improvements_153"></a> Conformance improvements in 15.3
748
748
749
749
### constexpr lambdas
750
750
@@ -786,7 +786,7 @@ The `*this` object in a lambda expression may now be captured by value. This cha
786
786
787
787
The `register` keyword, previously deprecated (and ignored by the compiler), is now removed from the language. For more information, see [Remove Deprecated Use of the register Keyword](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0001r1.html).
788
788
789
-
## <a name="improvements_155"></a> Improvements in Visual Studio 2017 version 15.5
789
+
## <a name="improvements_155"></a> Conformance improvements in 15.5
790
790
791
791
Features marked with \[14] are available unconditionally even in **/std:c++14** mode.
792
792
@@ -850,7 +850,7 @@ The standard library now uses variable templates internally.
850
850
851
851
The standard library has been updated in response to C++17 compiler changes, including the addition of `noexcept` in the type system and the removal of dynamic-exception-specifications.
852
852
853
-
## <a name="improvements_156"></a> Improvements in Visual Studio 2017 version 15.6
853
+
## <a name="improvements_156"></a> Conformance improvements in 15.6
854
854
855
855
### C++17 Library Fundamentals V1
856
856
@@ -860,7 +860,7 @@ The standard library has been updated in response to C++17 compiler changes, inc
860
860
861
861
[P0739R0](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0739r0.html) Move `adopt_lock_t` to front of parameter list for `scoped_lock` to enable consistent use of `scoped_lock`. Allow `std::variant` constructor to participate in overload resolution in more cases, to enable copy assignment.
862
862
863
-
## <a name="improvements_157"></a> Improvements in Visual Studio 2017 version 15.7
863
+
## <a name="improvements_157"></a> Conformance improvements in 15.7
864
864
865
865
### C++17: Rewording inheriting constructors
866
866
@@ -1032,7 +1032,7 @@ void sample(A<0> *p)
1032
1032
1033
1033
[P0426R1](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0426r1.html) Changes to `std::traits_type` member functions `length`, `compare`, and `find` to make `std::string_view` usable in constant expressions. (In Visual Studio 2017 version 15.6, supported for Clang/LLVM only. In version 15.7 Preview 2, support is nearly complete for ClXX as well.)
1034
1034
1035
-
## <aname="improvements_159"></a> Improvements in Visual Studio 2017 version 15.9
1035
+
## <aname="improvements_159"></a> Conformance improvements in 15.9
1036
1036
1037
1037
### Left-to-right evaluation order for operators `->*`, `[]`, `>>`, and `<<`
0 commit comments