Skip to content

Commit 1d62095

Browse files
author
Michael Blome
committed
changes per tech review
1 parent c7e6838 commit 1d62095

File tree

1 file changed

+42
-17
lines changed

1 file changed

+42
-17
lines changed

docs/cpp-conformance-improvements-2017.md

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ translation.priority.ht:
2929
---
3030

3131
# C++ conformance improvements in [!INCLUDE[vs_dev15_md](misc/includes/vs_dev15_md.md)]
32-
32+
For improvements in Update Version 15.3, see [Bug fixes in Visual Studio Update Version 15.3](#update_153).
3333
## New language features
3434
With support for generalized constexpr and NSDMI for aggregates, the compiler is now complete for features added in the C++14 Standard. Note that 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.
3535

@@ -349,9 +349,9 @@ void f(ClassLibrary1::Class1 ^r1, ClassLibrary1::Class2 ^r2)
349349
}
350350
```
351351

352-
## Visual Studio 2017 Updates
352+
## <a name="update_153"></a> Visual Studio 2017 Update Version 15.3
353353
### Calls to deleted member templates
354-
In previous versions of Visual Studio, the compiler in some cases would fail to emit an error for calls to a deleted member template. The following code now produces C2280, "'int S<int>::f<int>(void)': attempting to reference a deleted function":
354+
In previous versions of Visual Studio, the compiler in some cases would fail to emit an error for ill-formed calls to a deleted member template which would’ve potentially caused crashes at runtime. The following code now produces C2280, "'int S<int>::f<int>(void)': attempting to reference a deleted function":
355355
```cpp
356356
template<typename T>
357357
struct S {
@@ -366,7 +366,7 @@ decltype(S<int>::f<int>()) i; // this should fail
366366
To fix the error, declare i as `int`.
367367
368368
### Pre-condition checks for type traits
369-
Visual Studio 2017 Update 1 improves pre-condition checks for type-traits to more strictly follow the standard. One such check is for assignable. The following code produces C2139 in Update 1:
369+
Visual Studio 2017 Update Version 15.3 improves pre-condition checks for type-traits to more strictly follow the standard. One such check is for assignable. The following code produces C2139 in Update Version 15.3:
370370
371371
```cpp
372372
struct S;
@@ -379,7 +379,7 @@ static_assert(__is_convertible_to(E, E), "fail"); // this is allowed in VS2017 R
379379
### New compiler warning and runtime checks on native-to-managed marshaling
380380
Calling from managed functions to native functions requires marshalling. The CLR performs the marshaling but it doesn't understand C++ semantics. If you pass a native object by value, CLR will either call the object's copy-constructor or use BitBlt, which may cause undefined behavior at runtime.
381381

382-
Now the compiler will emit a warning if it can know at compile time that a native object with deleted copy ctor is passed between native and managed boundary by value. For those cases in which the compiler doesn't know at compile time, it will inject a runtime check so that the program will call std::terminate immediately when an ill-formed marshalling occurs. In Update 3, the following code produces C4606 "
382+
Now the compiler will emit a warning if it can know at compile time that a native object with deleted copy ctor is passed between native and managed boundary by value. For those cases in which the compiler doesn't know at compile time, it will inject a runtime check so that the program will call std::terminate immediately when an ill-formed marshalling occurs. In Update Version 15.3, the following code produces C4606 "
383383
'A': passing argument by value across native and managed boundary requires valid copy constructor. Otherwise the runtime behavior is undefined".
384384
```cpp
385385
class A
@@ -410,10 +410,10 @@ int main()
410410
f(A()); // This call from managed to native requires marshalling. The CLR doesn't understand C++ and uses BitBlt, which will result in a double-free later.
411411
}
412412
```
413-
To fix the error, mark the caller as native to avoid marshalling.
413+
To fix the error, remove the `#pragma managed` directive to mark the caller as native and avoid marshalling.
414414
415415
### Experimental API warning for WinRT
416-
WinRT APIs that are released for experimentation and feedback will be decorated with `Windows.Foundation.Metadata.ExperimentalAttribute`. In Update 3, the compiler will produce warning C4698 when it encounters the attribute. A few APIs in previous versions of the Windows SDK have already been decorated with the attribute, and calls to these APIs will start triggering this compiler warning. Newer Windows SDKs will have the attribute removed from all shipped types, but if you are using an older SDK, you'll need to suppress these warnings for all calls to shipped types.
416+
WinRT APIs that are released for experimentation and feedback will be decorated with `Windows.Foundation.Metadata.ExperimentalAttribute`. In Update Version 15.3, the compiler will produce warning C4698 when it encounters the attribute. A few APIs in previous versions of the Windows SDK have already been decorated with the attribute, and calls to these APIs will start triggering this compiler warning. Newer Windows SDKs will have the attribute removed from all shipped types, but if you are using an older SDK, you'll need to suppress these warnings for all calls to shipped types.
417417
The following code produces warning C4698: "'Windows::Storage::IApplicationDataStatics2::GetForUserAsync' is for evaluation purposes only and is subject to change or removal in future updates":
418418
```cpp
419419
Windows::Storage::IApplicationDataStatics2::GetForUserAsync()
@@ -430,7 +430,7 @@ Windows::Storage::IApplicationDataStatics2::GetForUserAsync()
430430
#pragma warning(pop)
431431
```
432432
### Out-of-line definition of a template member function
433-
Update 3 produces an error when it encounters an out-of-line definition of a template member function that was not declared in the class. The following code now produces error C2039: 'f': is not a member of 'S':
433+
Update Version 15.3 produces an error when it encounters an out-of-line definition of a template member function that was not declared in the class. The following code now produces error C2039: 'f': is not a member of 'S':
434434

435435
```cpp
436436
struct S {};
@@ -451,11 +451,11 @@ void S::f(T t) {}
451451
```
452452

453453
### Attempting to take the address of "this" pointer
454-
In C++ 'this' is an prvalue of type pointer to X. You cannot take the address of 'this' or bind it to an lvalue reference. In previous versions of Visual Studio, the compiler would allow you to circumvent this restriction by performing a cast. In Update 3, the compiler produces error C2664.
454+
In C++ 'this' is an prvalue of type pointer to X. You cannot take the address of 'this' or bind it to an lvalue reference. In previous versions of Visual Studio, the compiler would allow you to circumvent this restriction by performing a cast. In Update Version 15.3, the compiler produces error C2664.
455455

456456
### Conversion to an inaccessible base class
457-
Update 3 produces an error when you attempt to convert a type to a base class which is inaccessible. The following code now raises
458-
error C2243: 'type cast': conversion from 'D *' to 'B *' exists, but is inaccessible:
457+
Update Version 15.3 produces an error when you attempt to convert a type to a base class which is inaccessible. The compiler now raises
458+
"error C2243: 'type cast': conversion from 'D *' to 'B *' exists, but is inaccessible". The following code is ill-formed and can potentially cause a crash at runtime. The compiler now produces C2243 when it encounters code like this:
459459

460460
```cpp
461461
#include <memory>
@@ -470,7 +470,7 @@ void f()
470470
```
471471
### Default arguments are not allowed on out of line definitions of member functions
472472
Default arguments are not allowed on out-of-line definitions of member functions in template classes. The compiler will issue a warning under /permissive, and a hard error under /permissive-
473-
In Update 3, the following code produces warning C5034: 'A<T>::f': an out-of-line definition of a member of a class template cannot have default arguments:
473+
In previous versions of Visual Studio, the following ill-formed code could potentially cause a runtime crash. Update Version 15.3 produces warning C5034: 'A<T>::f': an out-of-line definition of a member of a class template cannot have default arguments:
474474
```cpp
475475
476476
template <typename T>
@@ -484,10 +484,10 @@ T A<T>::f(T t, bool b = false)
484484
...
485485
}
486486
```
487-
To fix the error, remove the "= false" default argument.
487+
To fix the error, remove the "= false" default argument.
488488

489489
### Use of offsetof with compound member designator
490-
In Update 3, using offsetof(T, m) where m is a "compound member designator" will result in a warning when you compile with the /Wall option. The following code produces "warning C4841: non-standard extension used: compound member designator in offseto":
490+
In Update Version 15.3, using offsetof(T, m) where m is a "compound member designator" will result in a warning when you compile with the /Wall option. The following code is ill-formed and could potentially cause crash at runtime. Update Version 15.3 produces "warning C4841: non-standard extension used: compound member designator in offseto":
491491

492492
```cpp
493493

@@ -508,7 +508,7 @@ constexpr auto off = offsetof(A, arr[2]);
508508
```
509509

510510
### Using offsetof with static data member or member function
511-
In Update 3, using offsetof(T, m) where m refers to a static data member or a member function will result in an error. The following code produces "error C4597: undefined behavior: offsetof applied to member function 'foo'" and "error C4597: undefined behavior: offsetof applied to static data member 'bar'":
511+
In Update Version 15.3, using offsetof(T, m) where m refers to a static data member or a member function will result in an error. The following code produces "error C4597: undefined behavior: offsetof applied to member function 'foo'" and "error C4597: undefined behavior: offsetof applied to static data member 'bar'":
512512
```cpp
513513

514514
#include <cstddef>
@@ -525,7 +525,7 @@ Constexpr auto off2 = offsetof(A, bar);
525525
This code is ill-formed and could potentially cause crash at runtime. To fix the error, change the code to no longer invoke undefined behavior. This is non-portable code that is disallowed by the C++ standard.
526526
527527
### New warning on declspec attributes
528-
In Update 3, the compiler no longer ignores attributes if __declspec(…) is applied before extern "C" linkage specification. Previously, the compiler would ignore the attritbute, which could have runtime implications. When the `/Wall /WX` option is set, the following code produces "warning C4768: __declspec attributes before linkage specification are ignored":
528+
In Update Version 15.3, the compiler no longer ignores attributes if __declspec(…) is applied before extern "C" linkage specification. Previously, the compiler would ignore the attritbute, which could have runtime implications. When the `/Wall /WX` option is set, the following code produces "warning C4768: __declspec attributes before linkage specification are ignored":
529529
530530
```cpp
531531
@@ -539,7 +539,7 @@ extern "C" __declspec(noinline) HRESULT __stdcall
539539
```
540540
541541
### decltype and calls to deleted destructors
542-
In previous versions of Visual Studio, the compiler did not detect when a call to a deleted destructor occurred in the context of the expression associated with 'decltype'. In Update 3, the following code produces "error C2280: 'A<T>::~A(void)': attempting to reference a deleted function":
542+
In previous versions of Visual Studio, the compiler did not detect when a call to a deleted destructor occurred in the context of the expression associated with 'decltype'. In Update Version 15.3, the following code produces "error C2280: 'A<T>::~A(void)': attempting to reference a deleted function":
543543
544544
```cpp
545545
template<typename T>
@@ -559,6 +559,31 @@ void h()
559559
g(42);
560560
}
561561
```
562+
### Unitialized const variables
563+
Visual Studio 2017 RTW release had a regression in which the C++ compiler would not issue a diagnostic if a 'const' variable was not initialized. This regression has been fixed in Visual Studio 2017 Update 1. The following code now produces "warning C4132: 'Value': const object should be initialized":
564+
565+
```cpp
566+
const int Value;
567+
```
568+
To fix the error, assign a value to `Value`.
569+
570+
### Empty declarations
571+
Visual Studio 2017 Update Version 15.3 now warns on empty declarions for all types, not just built-in types. The following code now produces a level 2 C4091 warning for all four declarations:
572+
573+
```cpp
574+
struct A {};
575+
template <typename> struct B {};
576+
enum C { c1, c2, c3 };
577+
578+
int; // warning C4091 : '' : ignored on left of 'int' when no variable is declared
579+
A; // warning C4091 : '' : ignored on left of 'main::A' when no variable is declared
580+
B<int>; // warning C4091 : '' : ignored on left of 'B<int>' when no variable is declared
581+
C; // warning C4091 : '' : ignored on left of 'C' when no variable is declared
582+
```
583+
584+
To remove the warnings, simply comment-out or remove the empty declarations. In cases where the un-named object is intended to have a side effect (such as RAII) it should be given a name.
585+
586+
The warning is excluded under /Wv:18 and is on by default under warning level W2.
562587
563588
564589
## See Also

0 commit comments

Comments
 (0)