Skip to content

Commit 709fef9

Browse files
author
mikeblome
committed
updates per AndrewM
1 parent 3485fbb commit 709fef9

1 file changed

Lines changed: 129 additions & 129 deletions

File tree

docs/overview/cpp-conformance-improvements.md

Lines changed: 129 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "C++ conformance improvements"
3-
ms.date: "08/28/2019"
3+
ms.date: "08/30/2019"
44
description: "Microsoft C++ in Visual Studio is progressing toward full conformance with the C++20 language standard."
55
ms.technology: "cpp-language"
66
author: "mikeblome"
@@ -12,7 +12,7 @@ Microsoft C++ makes conformance improvements and bug fixes in every release. Thi
1212

1313
::: moniker range="vs-2019"
1414

15-
## <a name="improvements_160"></a> Improvements in Visual Studio 2019 RTW (version 16.0)
15+
## <a name="improvements_160"></a> Conformance improvements in Visual Studio 2019 RTW (version 16.0)
1616

1717
Visual Studio 2019 RTW contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C++ compiler (MSVC)
1818

@@ -156,7 +156,7 @@ Implemented the `remove_cvref` and `remove_cvref_t` type traits from [P0550](htt
156156

157157
[C++20 P1008R1 - prohibiting aggregates with user-declared constructors](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf) is complete.
158158

159-
## <a name="improvements_161"></a> Improvements in Visual Studio 2019 version 16.1
159+
## <a name="improvements_161"></a> Conformance improvements in 16.1
160160

161161
### char8_t
162162

@@ -236,7 +236,7 @@ void f() {
236236
- `shift_left()` and `shift_right()` added to \<algorithm>.
237237

238238

239-
## <a name="improvements_162"></a> Improvements in Visual Studio 2019 version 16.2
239+
## <a name="improvements_162"></a> Conformance improvements in 16.2
240240

241241
### noexcept constexpr functions
242242

@@ -246,7 +246,7 @@ Constexpr functions are no longer considered `noexcept` by default when used in
246246
constexpr int f() { return 0; }
247247

248248
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
250250
}
251251
```
252252

@@ -256,7 +256,118 @@ To fix the error, add the `noexcept` expression to the function declaration:
256256
constexpr int f() noexcept { return 0; }
257257

258258
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+
enum E1 { 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+
enum E1 { 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+
enum E1 { 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+
enum E1 { 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+
int main() {
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+
int main() {
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:
328+
329+
```cpp
330+
std::equal(std::begin(a), std::end(a), std::begin(b), std::end(b));
331+
```
332+
333+
### 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+
struct S {
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;
260371
}
261372
```
262373
@@ -551,7 +662,7 @@ Fixed a regression in `std::pair`'s assignment operator introduced when implemen
551662
552663
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`.
553664
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
555666
556667
### Const comparators for associative containers
557668
@@ -601,122 +712,11 @@ struct Comparer {
601712

602713
```
603714
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-
enum E1 { 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-
enum E1 { 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-
enum E1 { 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-
int main() {
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-
int main() {
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:
669-
670-
```cpp
671-
std::equal(std::begin(a), std::end(a), std::begin(b), std::end(b));
672-
```
673-
674-
### 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-
struct S {
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-
715715
::: moniker-end
716716
717717
::: moniker range="vs-2017"
718718
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)
720720
721721
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.
722722
@@ -744,7 +744,7 @@ In **/std:c++17** mode, the `[[fallthrough]]` attribute can be used in the conte
744744
745745
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).
746746
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
748748
749749
### constexpr lambdas
750750
@@ -786,7 +786,7 @@ The `*this` object in a lambda expression may now be captured by value. This cha
786786
787787
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).
788788
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
790790
791791
Features marked with \[14] are available unconditionally even in **/std:c++14** mode.
792792
@@ -850,7 +850,7 @@ The standard library now uses variable templates internally.
850850
851851
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.
852852
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
854854
855855
### C++17 Library Fundamentals V1
856856
@@ -860,7 +860,7 @@ The standard library has been updated in response to C++17 compiler changes, inc
860860
861861
[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.
862862
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
864864
865865
### C++17: Rewording inheriting constructors
866866
@@ -1032,7 +1032,7 @@ void sample(A<0> *p)
10321032

10331033
[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.)
10341034

1035-
## <a name="improvements_159"></a> Improvements in Visual Studio 2017 version 15.9
1035+
## <a name="improvements_159"></a> Conformance improvements in 15.9
10361036

10371037
### Left-to-right evaluation order for operators `->*`, `[]`, `>>`, and `<<`
10381038

@@ -1389,7 +1389,7 @@ void f(ClassLibrary1::Class1 ^r1, ClassLibrary1::Class2 ^r2)
13891389
}
13901390
```
13911391

1392-
## <a name="update_153"></a> Bug fixes in Visual Studio 2017 version 15.3
1392+
## <a name="update_153"></a> Bug fixes in 15.3
13931393

13941394
### Calls to deleted member templates
13951395

@@ -1761,7 +1761,7 @@ To fix the problem, arrange the initializer list to have the same order as the d
17611761

17621762
This warning is off-by-default, and only affects code compiled with **/Wall**.
17631763

1764-
## <a name="update_155"></a> Bug fixes and other behavior changes in Visual Studio 2017 version 15.5
1764+
## <a name="update_155"></a> Bug fixes and other behavior changes in 15.5
17651765

17661766
### Partial ordering change
17671767

@@ -2220,7 +2220,7 @@ int main()
22202220
}
22212221
```
22222222
2223-
## <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
22242224
22252225
### C++17: Default argument in the primary class template
22262226
@@ -2356,7 +2356,7 @@ int main() {
23562356
}
23572357
```
23582358

2359-
## <a name="update_158"></a> Bug fixes and behavior changes in Visual Studio 2017 version 15.8
2359+
## <a name="update_158"></a> Bug fixes and behavior changes in 15.8
23602360

23612361
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:
23622362

@@ -2563,7 +2563,7 @@ struct X : Base<T>
25632563
};
25642564
```
25652565

2566-
## <a name="update_159"></a> Bug fixes and behavior changes in Visual Studio 2017 version 15.9
2566+
## <a name="update_159"></a> Bug fixes and behavior changes in 15.9
25672567

25682568
### Identifiers in member alias templates
25692569

0 commit comments

Comments
 (0)