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"
@@ -10,11 +10,11 @@ ms.author: "mblome"
10
10
11
11
Microsoft C++ makes conformance improvements and bug fixes in every release. This article lists the improvements by major release, then by version. It also lists major bug fixes by version. To jump directly to the changes for a specific version, use the **In this article** list.
12
12
13
-
::: moniker range=">=vs-2019"
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
-
Visual Studio 2019 RTW contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C++ compiler (MSVC).
17
+
Visual Studio 2019 RTW contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C++ compiler (MSVC)
18
18
19
19
**Note:** C++20 features will be made available in `/std:c++latest` mode until the C++20 implementation is complete for both the compiler and IntelliSense. At that time, the `/std:c++20` compiler mode will be introduced.
20
20
@@ -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
@@ -235,7 +235,154 @@ void f() {
235
235
-`remove()`, `remove_if()`, and `unique()` for `list` and `forward_list` now return `size_type`.
236
236
-`shift_left()` and `shift_right()` added to \<algorithm>.
237
237
238
-
## Bug fixes and behavior changes in Visual Studio 2019
238
+
239
+
## <aname="improvements_162"></a> Conformance improvements in 16.2
240
+
241
+
### noexcept constexpr functions
242
+
243
+
Constexpr functions are no longer considered `noexcept` by default when used in a constant expression. This behavior change comes from the resolution of [CWG 1351](http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1351) and is enabled in [/permissive-](../build/reference/permissive-standards-conformance.md). The following example compiles in Visual Studio 2019 version 16.1 and earlier, but produces C2338 in Visual Studio 2019 version 16.2:
244
+
245
+
```cpp
246
+
constexprintf() { return 0; }
247
+
248
+
int main() {
249
+
static_assert(noexcept(f()), "f should be noexcept"); // C2338 in 16.2
250
+
}
251
+
```
252
+
253
+
To fix the error, add the `noexcept` expression to the function declaration:
254
+
255
+
```cpp
256
+
constexprintf() noexcept { return 0; }
257
+
258
+
int main() {
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;
371
+
}
372
+
```
373
+
374
+
### Standard Library improvements
375
+
376
+
- \<charconv> `to_chars()` with fixed/scientific precision. (General precision is currently planned for 16.4.)
- [P0771R1](http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0771r1.pdf): noexcept For std::function's move constructor
384
+
385
+
## <a name="update_160"></a> Bug fixes and behavior changes in Visual Studio 2019
239
386
240
387
### Correct diagnostics for basic_string range constructor
241
388
@@ -515,11 +662,61 @@ Fixed a regression in `std::pair`'s assignment operator introduced when implemen
515
662
516
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`.
517
664
665
+
## <a name="update_162"></a> Bug fixes and behavior changes in 16.2
666
+
667
+
### Const comparators for associative containers
668
+
669
+
Code for search and insertion in [set](../standard-library/set-class.md), [map](../standard-library/map-class.md), [multiset](../standard-library/multiset-class.md), and [multimap](../standard-library/multimap-class.md) has been merged for reduced code size. Insertion operations now call the less-than comparison on a `const` comparison functor, in the same way that search operations have done previously. The following code compiles in Visual Studio 2019 version 16.1 and earlier, but raises C3848 in Visual Studio 2019 version 16.2:
670
+
671
+
```cpp
672
+
#include <iostream>
673
+
#include <map>
674
+
675
+
using namespace std;
676
+
677
+
struct K
678
+
{
679
+
int a;
680
+
string b = "label";
681
+
};
682
+
683
+
struct Comparer {
684
+
bool operator() (K a, K b) {
685
+
return a.a < b.a;
686
+
}
687
+
};
688
+
689
+
map<K, double, Comparer> m;
690
+
691
+
K const s1{1};
692
+
K const s2{2};
693
+
K const s3{3};
694
+
695
+
int main() {
696
+
697
+
m.emplace(s1, 1.08);
698
+
m.emplace(s2, 3.14);
699
+
m.emplace(s3, 5.21);
700
+
701
+
}
702
+
```
703
+
704
+
To avoid the error, make the comparison operator `const`:
705
+
706
+
```cpp
707
+
structComparer {
708
+
bool operator() (K a, K b) const {
709
+
return a.a < b.a;
710
+
}
711
+
};
712
+
713
+
```
714
+
518
715
::: moniker-end
519
716
520
-
::: moniker range=">=vs-2017"
717
+
::: moniker range="vs-2017"
521
718
522
-
## <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)
523
720
524
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.
525
722
@@ -547,7 +744,7 @@ In **/std:c++17** mode, the `[[fallthrough]]` attribute can be used in the conte
547
744
548
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).
549
746
550
-
## <a name="improvements_153"></a> Improvements in Visual Studio 2017 version 15.3
747
+
## <a name="improvements_153"></a> Conformance improvements in 15.3
551
748
552
749
### constexpr lambdas
553
750
@@ -589,7 +786,7 @@ The `*this` object in a lambda expression may now be captured by value. This cha
589
786
590
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).
591
788
592
-
## <a name="improvements_155"></a> Improvements in Visual Studio 2017 version 15.5
789
+
## <a name="improvements_155"></a> Conformance improvements in 15.5
593
790
594
791
Features marked with \[14] are available unconditionally even in **/std:c++14** mode.
595
792
@@ -653,7 +850,7 @@ The standard library now uses variable templates internally.
653
850
654
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.
655
852
656
-
## <a name="improvements_156"></a> Improvements in Visual Studio 2017 version 15.6
853
+
## <a name="improvements_156"></a> Conformance improvements in 15.6
657
854
658
855
### C++17 Library Fundamentals V1
659
856
@@ -663,7 +860,7 @@ The standard library has been updated in response to C++17 compiler changes, inc
663
860
664
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.
665
862
666
-
## <a name="improvements_157"></a> Improvements in Visual Studio 2017 version 15.7
863
+
## <a name="improvements_157"></a> Conformance improvements in 15.7
667
864
668
865
### C++17: Rewording inheriting constructors
669
866
@@ -835,7 +1032,7 @@ void sample(A<0> *p)
835
1032
836
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.)
837
1034
838
-
## <aname="improvements_159"></a> Improvements in Visual Studio 2017 version 15.9
1035
+
## <aname="improvements_159"></a> Conformance improvements in 15.9
839
1036
840
1037
### Left-to-right evaluation order for operators `->*`, `[]`, `>>`, and `<<`
## <aname="update_153"></a> Bug fixes in Visual Studio 2017 version 15.3
1392
+
## <aname="update_153"></a> Bug fixes in 15.3
1196
1393
1197
1394
### Calls to deleted member templates
1198
1395
@@ -1564,7 +1761,7 @@ To fix the problem, arrange the initializer list to have the same order as the d
1564
1761
1565
1762
This warning is off-by-default, and only affects code compiled with **/Wall**.
1566
1763
1567
-
## <aname="update_155"></a> Bug fixes and other behavior changes in Visual Studio 2017 version 15.5
1764
+
## <aname="update_155"></a> Bug fixes and other behavior changes in 15.5
1568
1765
1569
1766
### Partial ordering change
1570
1767
@@ -2023,7 +2220,7 @@ int main()
2023
2220
}
2024
2221
```
2025
2222
2026
-
## <a name="update_157"></a> Bug fixes and other behavior changes in Visual Studio 2017 version 15.7
2223
+
## <a name="update_157"></a> Bug fixes and other behavior changes in 15.7
2027
2224
2028
2225
### C++17: Default argument in the primary class template
2029
2226
@@ -2159,7 +2356,7 @@ int main() {
2159
2356
}
2160
2357
```
2161
2358
2162
-
## <aname="update_158"></a> Bug fixes and behavior changes in Visual Studio 2017 version 15.8
2359
+
## <aname="update_158"></a> Bug fixes and behavior changes in 15.8
2163
2360
2164
2361
The compiler changes in Visual Studio 2017 version 15.8 all fall under the category of bug fixes and behavior changes, and are listed below:
2165
2362
@@ -2366,7 +2563,7 @@ struct X : Base<T>
2366
2563
};
2367
2564
```
2368
2565
2369
-
## <aname="update_159"></a> Bug fixes and behavior changes in Visual Studio 2017 version 15.9
2566
+
## <aname="update_159"></a> Bug fixes and behavior changes in 15.9
2370
2567
2371
2568
### Identifiers in member alias templates
2372
2569
@@ -2551,10 +2748,14 @@ To avoid the error, remove the `constexpr` qualifier from the explicit instantia
2551
2748
2552
2749
::: moniker-end
2553
2750
2751
+
::: moniker range="vs-2015"
2752
+
2554
2753
## C++ conformance improvements in Visual Studio 2015
2555
2754
2556
2755
For the complete list of conformance improvements up through Visual Studio 2015 Update 3, see [Visual C++ What's New 2003 through 2015](/cpp/porting/visual-cpp-what-s-new-2003-through-2015).
2557
2756
2757
+
::: moniker-end
2758
+
2558
2759
## See also
2559
2760
2560
2761
[Visual C++ language conformance](../visual-cpp-language-conformance.md)
0 commit comments