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
Copy file name to clipboardExpand all lines: docs/overview/cpp-conformance-improvements.md
+147Lines changed: 147 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,156 @@ Visual Studio 2022 version 17.10 contains the following conformance improvements
21
21
22
22
For a broader summary of changes made to the Standard Template Library, see [STL Changelog VS 2022 17.10](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710).
23
23
24
+
---------------------- TW
25
+
### Conversion operator specialization with explicitly specified return type
24
26
27
+
This is a source code breaking change. The compiler used to specialize these conversion operators incorrectly in some cases which can lead to mismatched return type. These invalid specializations no longer happen.
25
28
29
+
#### Example (before/after)
30
+
31
+
```cpp
32
+
// Example 1
33
+
structS
34
+
{
35
+
template<typename T> operator const T*();
36
+
};
37
+
38
+
voidtest()
39
+
{
40
+
S{}.operator int*(); // this is invalid now
41
+
S{}.operator const int*(); // this is valid
42
+
}
43
+
```
44
+
45
+
```cpp
46
+
// Example 2
47
+
// In some cases, the overload resolution result may change
| Yes | C (C17 and later) | No | Unchanged | fe_20231031.02|
96
+
97
+
### Description/Rationale
98
+
In versions of Visual C++ before Visual Studio 2022 version 17.9, when the `_Alignas` specifier appeared adjacent to a structured type in a declaration, it was not applied correctly according to the ISO-C Standard.
According to the ISO-C Standard, this code should compile without the 'static_assert' emitting a diagnostic. The '_Alignas' directive applies only to the member variable 'member1'. It must not change the alignment of 'struct Inner'. However, before release 17.9.1 of Visual Studio, the diagnostic "incorrect alignment" would be emitted. The compiler would align 'member2' to an offset of 32 bytes within the 'struct Outer' type.
112
+
113
+
Since fixing this bug is a binary breaking change, a warning is now emitted when this change takes effect. Warning C5274 is now emitted at warning level 1 for the code above:
114
+
```
115
+
warning C5274: behavior change: _Alignas no longer applies to the type 'Inner' (only applies to declared data objects)
116
+
```
117
+
A second fix was made to _Alignof in this release. In previous versions of Visual Studio, when the _Alignas specifier appeared adjacent to an anonymous type declaration, it was ignored.
Previously, both `static_assert` statements would fail when this code was compiled. Now the code will compile, but with the following level 1 warnings emitted:
130
+
```
131
+
warning C5274: behavior change: _Alignas no longer applies to the type '<unnamed-tag>' (only applies to declared data objects)
132
+
warning C5273: behavior change: _Alignas on anonymous type no longer ignored (promoted members will align)
133
+
```
134
+
The previous behavior can be achieved by replacing uses of `_Alignas(N)` with `__declspec(align(N))`. This declspec is a documented feature of Visual C and C++ for many releases. Unlike `_Alignas`, use of `declspec(align)` will apply to the type.
Previously this warning was emitted by the optimizer, c2.dll: one side-effect of this was that the compiler could not detect the convention for suppressing the warning: i.e., wrapping the assignment in parentheses (if an assignment really was intended). By moving the warning from the optimizer to the parser, c1.dll or c1xx.dll, the compiler can now detect the parentheses and hence suppress the warning in these cases.
146
+
147
+
When the warning was in the optimizer it would only check functions that were, in some way, referenced and hence passed to the optimizer to process. If a function was not referenced, then the optimizer would never see it and the warning would not be emitted.
148
+
149
+
Now that the warning is in the parser it will be emitted for all functions regardless of whether they are referenced or not.
150
+
151
+
### Example
152
+
```
153
+
#pragma warning(error: 4706)
154
+
155
+
struct S {
156
+
auto mf() {
157
+
if (value = 9)
158
+
return value + 4;
159
+
else
160
+
return value;
161
+
}
162
+
163
+
int value = 9;
164
+
};
165
+
```
166
+
Previously, as 'mf' is an inline function that is never referenced, it would not be passed to the optimizer and hence warning C4706 would not be emitted for this code: but now that the parser is being used to detect this situation the warning is emitted.
167
+
```
168
+
t.cpp(5): error C4706: assignment used as a condition
169
+
t.cpp(5): note: if an assignment is intended you can enclose it in parentheses, '(e1 = e2)', to silence this warning
170
+
```
171
+
The fix is to either switch to an equality operator, 'value == 9', if this is what was intended, or to wrap the assignment in parentheses, '(value = 9)', if an assignment really was intended. Or, as the function is unreferenced, it can be removed.
26
172
173
+
---------------------- /TW
27
174
28
175
## <aname="improvements_179"></a> Conformance improvements in Visual Studio 2022 version 17.9
0 commit comments