Skip to content

Commit f3a8763

Browse files
author
mikeblome
committed
added error code to some code snippets
1 parent 2e1fcbb commit f3a8763

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

docs/cpp-conformance-improvements-2017.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
title: "C++ compiler conformance improvements | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/16/2016"
4+
ms.date: "06/05/2017"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology:
88
- "vs-ide-general"
99
ms.tgt_pltfrm: ""
1010
ms.topic: "article"
1111
ms.assetid: 8801dbdb-ca0b-491f-9e33-01618bff5ae9
12-
author: "BrianPeek"
13-
ms.author: "brpeek"
12+
author: "mikeblome"
13+
ms.author: "mblome"
1414
manager: "ghogen"
1515
translation.priority.ht:
1616
- "cs-cz"
@@ -143,7 +143,7 @@ int main()
143143
```
144144

145145
### constexpr
146-
Visual Studio 2017 correctly raises an error when the left-hand operand of a conditionally evaluating operation is not valid in a constexpr context. The following code compiles in Visual Studio 2015 but not in Visual Studio 2017:
146+
Visual Studio 2017 correctly raises an error when the left-hand operand of a conditionally evaluating operation is not valid in a constexpr context. The following code compiles in Visual Studio 2015 but not in Visual Studio 2017 (C3615 constexpr function 'f' cannot result in a constant expression):
147147

148148
```cpp
149149
template<int N>
@@ -154,7 +154,7 @@ struct array
154154

155155
constexpr bool f(const array<1> &arr)
156156
{
157-
return arr.size() == 10 || arr.size() == 11; // error starting in Visual Studio 2017
157+
return arr.size() == 10 || arr.size() == 11; // C3615
158158
}
159159
```
160160
To correct the error, either declare the array::size() function as constexpr or remove the constexpr qualifier from f.
@@ -372,8 +372,8 @@ Visual Studio 2017 Update Version 15.3 improves pre-condition checks for type-tr
372372
struct S;
373373
enum E;
374374
375-
static_assert(!__is_assignable(S, S), "fail"); // this is allowed in VS2017 RTM, but should fail
376-
static_assert(__is_convertible_to(E, E), "fail"); // this is allowed in VS2017 RTM, but should fail
375+
static_assert(!__is_assignable(S, S), "fail"); // C2139 in 15.3
376+
static_assert(__is_convertible_to(E, E), "fail"); // C2139 in 15.3
377377
```
378378

379379
### New compiler warning and runtime checks on native-to-managed marshaling
@@ -416,7 +416,7 @@ To fix the error, remove the `#pragma managed` directive to mark the caller as n
416416
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
419-
Windows::Storage::IApplicationDataStatics2::GetForUserAsync()
419+
Windows::Storage::IApplicationDataStatics2::GetForUserAsync() //C4698
420420
```
421421

422422
To disable the warning, add a #pragma:
@@ -436,7 +436,7 @@ Update Version 15.3 produces an error when it encounters an out-of-line definiti
436436
struct S {};
437437

438438
template <typename T>
439-
void S::f(T t) {}
439+
void S::f(T t) {} //C2039: 'f': is not a member of 'S'
440440
```
441441
442442
To fix the error, add a declaration to the class:
@@ -461,7 +461,7 @@ Update Version 15.3 produces an error when you attempt to convert a type to a ba
461461
#include <memory>
462462

463463
class B { };
464-
class D : B { }; // should be public B { };
464+
class D : B { }; // C2243. should be public B { };
465465

466466
void f()
467467
{
@@ -479,7 +479,7 @@ struct A {
479479
};
480480
481481
template <typename T>
482-
T A<T>::f(T t, bool b = false)
482+
T A<T>::f(T t, bool b = false) // C5034
483483
{
484484
...
485485
}
@@ -529,7 +529,7 @@ In Update Version 15.3, the compiler no longer ignores attributes if __declspec(
529529
530530
```cpp
531531
532-
__declspec(noinline) extern "C" HRESULT __stdcall
532+
__declspec(noinline) extern "C" HRESULT __stdcall //C4768
533533
```
534534

535535
To fix the warning, put extern "C" first:
@@ -564,7 +564,7 @@ void h()
564564
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":
565565

566566
```cpp
567-
const int Value;
567+
const int Value; //C4132
568568
```
569569
To fix the error, assign a value to `Value`.
570570

@@ -649,7 +649,7 @@ void f()
649649
using N::f;
650650
651651
S s1, s2;
652-
f(s1, s2);
652+
f(s1, s2); // C2668
653653
}
654654
```
655655
To fix the code, remove the using N::f statement if you intended to call ::f().
@@ -664,7 +664,8 @@ void f(S, int);
664664

665665
void g()
666666
{
667-
void f(S); // or void f(S, int);
667+
void f(S); // C2660 'f': function does not take 2 arguments:
668+
// or void f(S, int);
668669
S s;
669670
f(s, 0);
670671
}

0 commit comments

Comments
 (0)