Skip to content

Commit 507b1fe

Browse files
author
Colin Robertson
authored
Fix error and warnings issues (#406)
* Updated errors and warnings * Metadata tag update * Update warning as error and off by default * Fix link issue, target format
1 parent 670dd96 commit 507b1fe

18 files changed

Lines changed: 1759 additions & 1633 deletions

docs/build/includes/vcprvc_md.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
---
2-
---
31
Visual C++
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: "Compiler Error C2672 | Microsoft Docs"
3+
ms.date: "10/24/2017"
4+
ms.technology: ["cpp-tools"]
5+
ms.topic: "error-reference"
6+
f1_keywords: ["C2672"]
7+
dev_langs: ["C++"]
8+
helpviewer_keywords: ["C2672"]
9+
ms.assetid: 7e86338a-2d4b-40fe-9dd2-ac6886f3f31a
10+
author: "corob-msft"
11+
ms.author: "corob"
12+
manager: "ghogen"
13+
---
14+
# Compiler Error C2672
15+
16+
> '*function*': no matching overloaded function found
17+
18+
The compiler could not find an overloaded function that matches the specified function. No function was found that takes matching parameters, or no matching function has the required accessibility in context.
19+
20+
When used by certain standard library containers or algorithms, your types must provide accessible members or friend functions that satisfy the requirements of the container or algorithm. For example, your iterator types should derive from `std::iterator<>`. Comparison operations or use of other operators on container element types may require the type be considered as both a left-hand and a right-hand operand. Use of the type as a right-hand operand can require implementation of the operator as a non-member function of the type.
21+
22+
## Example
23+
24+
Versions of the compiler before Visual Studio 2017 did not perform access checking on qualified names in some template contexts. This can interfere with expected SFINAE behavior where the substitution is expected to fail due to the inaccessibility of a name. This could have potentially caused a crash or unexpected behavior at runtime due to the compiler incorrectly calling the wrong overload of the operator. In Visual Studio 2017, a compiler error is raised.
25+
26+
This example compiles in Visual Studio 2015 but raises an error in Visual Studio 2017. To fix this issue, make the template parameter member accessible where it is evaluated.
27+
28+
```cpp
29+
#include <type_traits>
30+
31+
template <class T> class S {
32+
// public: // Uncomment this line to fix
33+
typedef typename T type;
34+
};
35+
36+
template <class T, std::enable_if<std::is_integral<typename S<T>::type>::value, T> * = 0>
37+
bool f(T x)
38+
{
39+
return (x == 0);
40+
}
41+
42+
int main()
43+
{
44+
f(10); // C2672: No matching overloaded function found.
45+
}
46+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Compiler Error C3615 | Microsoft Docs"
3+
ms.date: "10/24/2017"
4+
ms.technology: ["cpp-tools"]
5+
ms.topic: "error-reference"
6+
f1_keywords: ["C3615"]
7+
dev_langs: ["C++"]
8+
helpviewer_keywords: ["C3615"]
9+
ms.assetid: 5ce96ba9-3d31-49f3-9aa8-24e5cdf6dcfc
10+
author: "corob-msft"
11+
ms.author: "corob"
12+
manager: "ghogen"
13+
---
14+
# Compiler Error C3615
15+
16+
> constexpr function '*function*' cannot result in a constant expression
17+
18+
The function *function* could not be evaluated as `constexpr` at compile time. To be `constexpr`, a function can only call other `constexpr` functions.
19+
20+
## Example
21+
22+
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.
23+
24+
```cpp
25+
// C3615.cpp
26+
// Compile with: /c
27+
28+
template<int N>
29+
struct myarray
30+
{
31+
int size() const { return N; }
32+
};
33+
34+
constexpr bool f(const myarray<1> &arr)
35+
{
36+
return arr.size() == 10 || arr.size() == 11; // C3615 starting in Visual Studio 2017
37+
}
38+
```
39+
40+
To fix this issue, either declare the `array::size()` function as `constexpr` or remove the `constexpr` qualifier from `f`.

docs/error-messages/compiler-errors-2/compiler-errors-c2600-through-c2699.md

Lines changed: 111 additions & 115 deletions
Large diffs are not rendered by default.

docs/error-messages/compiler-errors-2/compiler-errors-c3500-through-c3999.md

Lines changed: 510 additions & 514 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: "Compiler Warning C4693 | Microsoft Docs"
3-
ms.custom: ""
4-
ms.date: "11/04/2016"
3+
ms.date: "10/25/2017"
54
ms.reviewer: ""
65
ms.suite: ""
76
ms.technology: ["cpp-tools"]
@@ -17,19 +16,23 @@ ms.author: "corob"
1716
manager: "ghogen"
1817
---
1918
# Compiler Warning C4693
20-
'class': a sealed abstract class cannot have any instance members 'Test'
21-
22-
If a type is marked [sealed](../../windows/sealed-cpp-component-extensions.md) and [abstract](../../windows/abstract-cpp-component-extensions.md), it can only have static members.
23-
24-
## Example
25-
The following sample generates C4693.
26-
27-
```
28-
// C4693.cpp
29-
// compile with: /clr /c
30-
public ref class Public_Ref_Class sealed abstract {
31-
public:
32-
void Test() {} // C4693
33-
static void Test2() {} // OK
34-
};
19+
20+
> 'class': a sealed abstract class cannot have any instance members 'Test'
21+
22+
If a type is marked [sealed](../../windows/sealed-cpp-component-extensions.md) and [abstract](../../windows/abstract-cpp-component-extensions.md), it can only have static members.
23+
24+
This warning is automatically promoted to an error. If you wish to modify this behavior, use [#pragma warning](../../preprocessor/warning.md).
25+
26+
## Example
27+
28+
The following sample generates C4693.
29+
30+
```cpp
31+
// C4693.cpp
32+
// compile with: /clr /c
33+
public ref class Public_Ref_Class sealed abstract {
34+
public:
35+
void Test() {} // C4693
36+
static void Test2() {} // OK
37+
};
3538
```
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
---
22
title: "Compiler Warning C4694 | Microsoft Docs"
3-
ms.custom: ""
4-
ms.date: "11/04/2016"
5-
ms.reviewer: ""
6-
ms.suite: ""
3+
ms.date: "10/25/2017"
74
ms.technology: ["cpp-tools"]
8-
ms.tgt_pltfrm: ""
95
ms.topic: "article"
106
f1_keywords: ["C4694"]
117
dev_langs: ["C++"]
128
helpviewer_keywords: ["C4694"]
139
ms.assetid: 5ca122bb-34f3-43ee-a21f-95802cd515f7
14-
caps.latest.revision: 3
1510
author: "corob-msft"
1611
ms.author: "corob"
1712
manager: "ghogen"
1813
---
1914
# Compiler Warning C4694
20-
'class_1': a sealed abstract class cannot have a base-class 'base_class'
21-
22-
An abstract and sealed class cannot inherit from a reference type; a sealed and abstract class can neither implement the base class functions nor allow itself to be used as a base class.
23-
24-
For more information, see [abstract](../../windows/abstract-cpp-component-extensions.md), [sealed](../../windows/sealed-cpp-component-extensions.md), and [Classes and Structs](../../windows/classes-and-structs-cpp-component-extensions.md).
25-
26-
## Example
27-
The following sample generates C4694.
28-
29-
```
30-
// C4694.cpp
31-
// compile with: /c /clr
32-
ref struct A {};
33-
ref struct B sealed abstract : A {}; // C4694
15+
16+
> '*class*': a sealed abstract class cannot have a base-class '*base_class*'
17+
18+
An abstract and sealed class cannot inherit from a reference type; a sealed and abstract class can neither implement the base class functions nor allow itself to be used as a base class.
19+
20+
For more information, see [abstract](../../windows/abstract-cpp-component-extensions.md), [sealed](../../windows/sealed-cpp-component-extensions.md), and [Classes and Structs](../../windows/classes-and-structs-cpp-component-extensions.md).
21+
22+
This warning is automatically promoted to an error. If you wish to modify this behavior, use [#pragma warning](../../preprocessor/warning.md).
23+
24+
## Example
25+
26+
The following sample generates C4694.
27+
28+
```cpp
29+
// C4694.cpp
30+
// compile with: /c /clr
31+
ref struct A {};
32+
ref struct B sealed abstract : A {}; // C4694
3433
```
Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,65 @@
11
---
22
title: "Compiler Warning C4868 | Microsoft Docs"
3-
ms.custom: ""
4-
ms.date: "11/04/2016"
5-
ms.reviewer: ""
6-
ms.suite: ""
7-
ms.tgt_pltfrm: ""
3+
ms.date: "10/26/2017"
84
ms.topic: "error-reference"
95
f1_keywords: ["C4868"]
106
ms.assetid: fc6aa7e5-34dd-4ec2-88bd-16e430361dc7
11-
caps.latest.revision: 4
127
author: "corob-msft"
138
ms.author: "corob"
149
manager: "ghogen"
1510
---
16-
# Compiler Warning C4868
17-
'file(line_number)' compiler may not enforce left-to-right evaluation order in braced initializer list
18-
19-
The elements of a braced initializer list are to be evaluated in left-to-right order. There are two cases in which the compiler is unable to guarantee this order: the first is when some of the elements are objects passed by value; the second is when compiling with `/clr` and some of the elements are fields of objects or are array elements. When the compiler can't guarantee left-to-right evaluation it emits warning C4868.
20-
21-
This warning can be generated as a result of compiler conformance work that was done for Visual C++ 2015 Update 2. Code that compiled prior to Visual C++ 2015 Update 2 will now generate C4868.
22-
23-
This warning is off by default. Use `/Wall` to activate this warning.
24-
25-
To resolve this warning, first consider whether left-to-right evaluation of the initializer list elements is necessary, such as when evaluation of the elements might produce order-dependent side-effects. In many cases, the order in which elements are evaluated does not have an observable effect.
26-
27-
If the order of evaluation must be left-to-right, consider if it's possible to pass the elements by (const) reference instead. A change such as this eliminates the warning in the following code sample.
28-
29-
## Example
30-
The following sample generates C4868.
31-
32-
```
33-
// C4868.cpp
34-
// compile with: /c /Wall
35-
#include <cstdio>
36-
37-
class HasCopyConstructor
38-
{
39-
public:
40-
int x;
41-
42-
HasCopyConstructor(int x): x(x) {}
43-
44-
HasCopyConstructor(const HasCopyConstructor& h): x(h.x)
45-
{
46-
printf("Constructing %d\n", h.x);
47-
}
48-
};
49-
50-
class TripWarning4868
51-
{
52-
public:
53-
// note that taking "HasCopyConstructor" parameters by-value will trigger copy-construction.
54-
TripWarning4868(HasCopyConstructor a, HasCopyConstructor b) {}
55-
56-
// This variation will not trigger the warning:
57-
// TripWarning4868(const HasCopyConstructor& a, const HasCopyConstructor& b) {}
58-
};
59-
60-
int main()
61-
{
62-
HasCopyConstructor a{1};
63-
HasCopyConstructor b{2};
64-
65-
// the warning will indicate the below line, the usage of the braced initializer list.
66-
TripWarning4868 warningOnThisLine{a, b};
67-
};
11+
# Compiler Warning (level 4) C4868
12+
13+
> '_file_(*line_number*)' compiler may not enforce left-to-right evaluation order in braced initializer list
14+
15+
The elements of a braced initializer list are to be evaluated in left-to-right order. There are two cases in which the compiler is unable to guarantee this order: the first is when some of the elements are objects passed by value; the second is when compiling with `/clr` and some of the elements are fields of objects or are array elements. When the compiler can't guarantee left-to-right evaluation it emits warning C4868.
16+
17+
This warning can be generated as a result of compiler conformance work that was done for Visual C++ 2015 Update 2. Code that compiled prior to Visual C++ 2015 Update 2 can now generate C4868.
18+
19+
This warning is off by default. Use `/Wall` to activate this warning.
20+
21+
To resolve this warning, first consider whether left-to-right evaluation of the initializer list elements is necessary, such as when evaluation of the elements might produce order-dependent side-effects. In many cases, the order in which elements are evaluated does not have an observable effect.
22+
23+
If the order of evaluation must be left-to-right, consider if it's possible to pass the elements by `const` reference instead. A change such as this eliminates the warning in the following code sample.
24+
25+
## Example
26+
27+
This sample generates C4868, and shows a way to fix it:
28+
29+
```cpp
30+
// C4868.cpp
31+
// compile with: /c /Wall
32+
#include <cstdio>
33+
34+
class HasCopyConstructor
35+
{
36+
public:
37+
int x;
38+
39+
HasCopyConstructor(int x): x(x) {}
40+
41+
HasCopyConstructor(const HasCopyConstructor& h): x(h.x)
42+
{
43+
printf("Constructing %d\n", h.x);
44+
}
45+
};
46+
47+
class TripWarning4868
48+
{
49+
public:
50+
// note that taking "HasCopyConstructor" parameters by-value will trigger copy-construction.
51+
TripWarning4868(HasCopyConstructor a, HasCopyConstructor b) {}
52+
53+
// This variation will not trigger the warning:
54+
// TripWarning4868(const HasCopyConstructor& a, const HasCopyConstructor& b) {}
55+
};
56+
57+
int main()
58+
{
59+
HasCopyConstructor a{1};
60+
HasCopyConstructor b{2};
61+
62+
// the warning will indicate the below line, the usage of the braced initializer list.
63+
TripWarning4868 warningOnThisLine{a, b};
64+
};
6865
```
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
---
22
title: "Compiler Warning (level 1) C4226 | Microsoft Docs"
3-
ms.custom: ""
4-
ms.date: "11/04/2016"
5-
ms.reviewer: ""
6-
ms.suite: ""
3+
ms.date: "10/25/2017"
74
ms.technology: ["cpp-tools"]
8-
ms.tgt_pltfrm: ""
95
ms.topic: "error-reference"
106
f1_keywords: ["C4226"]
117
dev_langs: ["C++"]
128
helpviewer_keywords: ["C4226"]
139
ms.assetid: 69d6bbde-1300-4e48-8a9c-3648c80ab441
14-
caps.latest.revision: 6
1510
author: "corob-msft"
1611
ms.author: "corob"
1712
manager: "ghogen"
1813
---
1914
# Compiler Warning (level 1) C4226
20-
nonstandard extension used : 'keyword' is an obsolete keyword
21-
22-
The current version of Visual C++ does not use this keyword.
15+
16+
> nonstandard extension used : '*keyword*' is an obsolete keyword
17+
18+
The current version of Visual C++ does not use this keyword.
19+
20+
This warning is automatically promoted to an error.

0 commit comments

Comments
 (0)