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
title: "C++ compiler conformance improvements | Microsoft Docs"
3
3
ms.custom: ""
4
-
ms.date: "11/16/2016"
4
+
ms.date: "06/05/2017"
5
5
ms.reviewer: ""
6
6
ms.suite: ""
7
7
ms.technology:
8
8
- "vs-ide-general"
9
9
ms.tgt_pltfrm: ""
10
10
ms.topic: "article"
11
11
ms.assetid: 8801dbdb-ca0b-491f-9e33-01618bff5ae9
12
-
author: "BrianPeek"
13
-
ms.author: "brpeek"
12
+
author: "mikeblome"
13
+
ms.author: "mblome"
14
14
manager: "ghogen"
15
15
translation.priority.ht:
16
16
- "cs-cz"
@@ -143,7 +143,7 @@ int main()
143
143
```
144
144
145
145
### 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):
147
147
148
148
```cpp
149
149
template<int N>
@@ -154,7 +154,7 @@ struct array
154
154
155
155
constexprboolf(const array<1> &arr)
156
156
{
157
-
return arr.size() == 10 || arr.size() == 11; // error starting in Visual Studio 2017
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
372
372
struct S;
373
373
enum E;
374
374
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
377
377
```
378
378
379
379
### 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
416
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.
417
417
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":
This warning is off-by-default and only impacts code compiled with `/Wall /WX`.
540
541
541
542
### decltype and calls to deleted destructors
542
543
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":
@@ -563,7 +564,7 @@ void h()
563
564
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
565
566
```cpp
566
-
constint Value;
567
+
constint Value;//C4132
567
568
```
568
569
To fix the error, assign a value to `Value`.
569
570
@@ -586,5 +587,107 @@ To remove the warnings, simply comment-out or remove the empty declarations. In
586
587
The warning is excluded under /Wv:18 and is on by default under warning level W2.
587
588
588
589
590
+
### std::is_convertible for array types
591
+
Previous versions of the compiler gave incorrect results for [std::is_convertible](standard-library/is-convertible-class.md) for array types. This required library writers to special-case the Visual C++ compiler when using the `std::is_convertable<…>` type trait. In the following example, the static asserts pass in earlier versions of Visual Studio but fail in Visual Studio 2017 Update Version 15.3:
**std::is_convertible<From, To>** is calculated by checking to see if an imaginary function definition is well formed:
605
+
```cpp
606
+
To test() { return std::declval<From>(); }
607
+
```
608
+
609
+
### Private destructors and std::is_constructible
610
+
Previous versions of the compiler ignore whether a destructor was private when decided the result of [std::is_constructible](standard-library/is-constructible-class.md). It now considers them. In the following example, the static asserts pass in earlier versions of Visual Studio but fail in Visual Studio 2017 Update Version 15.3:
611
+
612
+
```cpp
613
+
#include <type_traits>
614
+
615
+
class PrivateDtor {
616
+
PrivateDtor(int) { }
617
+
private:
618
+
~PrivateDtor() { }
619
+
};
620
+
621
+
// This assertion used to succeed. It now correctly fails.
Private destructors cause a type to be non-constructible. **std::is_constructible<T, Args…>** is calculated as if the following declaration were written:
626
+
```cpp
627
+
T obj(std::declval<Args>()…)
628
+
```
629
+
This call implies a destructor call.
630
+
631
+
### C2668: Ambiguous overload resolution
632
+
Previous versions of the compiler sometimes failed to detect ambiguity when it found multiple candidates via both using declarations and argument dependent lookups. This can lead to wrong overload being chosen and unexpected runtime behavior. In the following example, Visual Studio 2017 Update Version 15.3 correctly raises C2668 'f': ambiguous call to overloaded function:
633
+
634
+
```cpp
635
+
namespace N {
636
+
template<class T>
637
+
void f(T&, T&);
638
+
639
+
template<class T>
640
+
void f();
641
+
}
642
+
643
+
template<class T>
644
+
void f(T&, T&);
645
+
646
+
struct S {};
647
+
void f()
648
+
{
649
+
using N::f;
650
+
651
+
S s1, s2;
652
+
f(s1, s2); // C2668
653
+
}
654
+
```
655
+
To fix the code, remove the using N::f statement if you intended to call ::f().
656
+
657
+
### C2660: local function declarations and argument dependent lookup
658
+
Local function declarations hide the function declaration in the enclosing scope and disable argument dependent lookup.
659
+
However, previous versions of the Visual C++ compiler performed argument dependent lookup in this case, potentially leading to the wrong overload being chosen and unexpected runtime behavior. Typically, the error is due to an incorrect signature of the local function declaration. In the following example, Visual Studio 2017 Update Version 15.3 correctly raises C2660 'f': function does not take 2 arguments:
660
+
661
+
```cpp
662
+
structS {};
663
+
void f(S, int);
664
+
665
+
void g()
666
+
{
667
+
void f(S); // C2660 'f': function does not take 2 arguments:
668
+
// or void f(S, int);
669
+
S s;
670
+
f(s, 0);
671
+
}
672
+
```
673
+
674
+
To fix the problem, either change the **f(S)** signature or remove it.
675
+
676
+
### C5038: order of initialization in initializer lists
677
+
Class members are initialized in the order they are declared, not the order they appear in initializer lists. Previous versions of the compiler did not warn when the order of the initializer list differed from the order of declaration. This could lead to undefined runtime behavior if the intialization of one member depended on another member in the list already being initialized. In the following example, Visual Studio 2017 Update Version 15.3 (with /Wall or /WX) raises warning C5038: data member 'A::y' will be initialized after data member 'A::x':
678
+
679
+
```cpp
680
+
struct A
681
+
{
682
+
A(int a) : y(a), x(y) {} // Initialized in reverse, y reused
683
+
int x;
684
+
int y;
685
+
};
686
+
687
+
```
688
+
To fix the problem arrange the intializer list to have the same order as the declarations. A similar warning is raised when one or both initializers refer to base class members.
689
+
690
+
Note that the warning is off-by-default and only affects code compiled with /Wall or /WX.
691
+
589
692
## See Also
590
693
[Visual C++ Language Conformance](visual-cpp-language-conformance.md)
Copy file name to clipboardExpand all lines: docs/porting/visual-cpp-what-s-new-2003-through-2015.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1383,7 +1383,7 @@ In Visual C++ 2015 and later, ongoing improvements to compiler conformance can s
1383
1383
warning C4467: Usage of ATL attributes is deprecated
1384
1384
```
1385
1385
1386
-
If you want to continue using attributed ATL code until support is removed from the compiler, you can disable this warning by passing the `/Wv:18` or `/wd:4467` command line arguments to the compiler, or by adding `#pragma warning(disable:4467)` in your source code.
1386
+
If you want to continue using attributed ATL code until support is removed from the compiler, you can disable this warning by passing the `/Wv:18` or `/wd4467` command line arguments to the compiler, or by adding `#pragma warning(disable:4467)` in your source code.
0 commit comments