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
A *hidden friend* is a friend declaration of a function or function template within a class or
12
+
class template definition, that declaration shall be the only declaration of that function or function template
13
+
provided by an implementation.
14
+
15
+
The C++20 standard . This change can cause a number of source compatibility issues in code that conforms to C++14 or earlier. The **`/Zc:hiddenFriend`** option specifies conformance to the C++17 standard. **`/Zc:hiddenFriend-`** allows the C++14 and earlier behavior when code is compiled in C++17 mode.
16
+
17
+
## Syntax
18
+
19
+
> **`/Zc:hiddenFriend`**\[**`-`**]
20
+
21
+
## Remarks
22
+
23
+
When the **`/Zc:hiddenFriend`** option is specified, the compiler conforms to the C++17 standard and treats [`throw()`](../../cpp/exception-specifications-throw-cpp.md) as an alias for [`noexcept`](../../cpp/noexcept-cpp.md), removes `throw(`*`type-list`*`)` and `throw(...)`, and allows certain types to include **`noexcept`**. The **`/Zc:hiddenFriend`** option is only available when [`/std:c++17`](std-specify-language-standard-version.md) or [`/std:c++latest`](std-specify-language-standard-version.md) is enabled. **`/Zc:hiddenFriend`** is enabled by default to conform to the ISO C++17 standard. The [`/permissive-`](permissive-standards-conformance.md) option doesn't affect **`/Zc:hiddenFriend`**. Turn off this option by specifying **`/Zc:hiddenFriend-`** to revert to the C++14 behavior of **`noexcept`** when **`/std:c++17`** or **`/std:c++latest`** is specified.
24
+
25
+
Beginning in Visual Studio 2017 version 15.5, the C++ compiler diagnoses more mismatched exception specifications in declarations in C++17 mode, or when you specify the [`/permissive-`](permissive-standards-conformance.md) option.
26
+
27
+
This sample shows how declarations with an exception specifier behave when the **`/Zc:hiddenFriend`** option is set or disabled. To show the behavior when set, compile by using `cl /EHsc /W4 hiddenFriend.cpp`. To show the behavior when disabled, compile by using `cl /EHsc /W4 /Zc:hiddenFriend- hiddenFriend.cpp`.
28
+
29
+
```cpp
30
+
// hiddenFriend.cpp
31
+
// Compile by using: cl /EHsc /W4 hiddenFriend.cpp
32
+
// Compile by using: cl /EHsc /W4 /Zc:hiddenFriend- hiddenFriend.cpp
33
+
34
+
voidf() throw(); // equivalent to void f() noexcept;
35
+
voidf() { } // warning C5043
36
+
void g() throw(...); // warning C5040
37
+
38
+
struct A
39
+
{
40
+
virtual void f() throw();
41
+
};
42
+
43
+
struct B : A
44
+
{
45
+
virtual void f() { } // error C2694
46
+
};
47
+
```
48
+
49
+
When compiled by using the default setting **`/Zc:hiddenFriend`**, the sample generates the listed warnings. To update your code, use the following instead:
50
+
51
+
```cpp
52
+
void f() noexcept;
53
+
void f() noexcept { }
54
+
void g() noexcept(false);
55
+
56
+
struct A
57
+
{
58
+
virtual void f() noexcept;
59
+
};
60
+
61
+
struct B : A
62
+
{
63
+
virtual void f() noexcept { }
64
+
};
65
+
```
66
+
67
+
For more information about conformance issues in Visual C++, see [Nonstandard Behavior](../../cpp/nonstandard-behavior.md).
68
+
69
+
### To set this compiler option in the Visual Studio development environment
70
+
71
+
1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
Copy file name to clipboardExpand all lines: docs/overview/cpp-conformance-improvements.md
+32-17Lines changed: 32 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1153,29 +1153,44 @@ void f() {
1153
1153
<!-- TODO 16.8 -->
1154
1154
## <aname="improvements_168"></a> Conformance improvements in Visual Studio 2019 version 16.8
1155
1155
1156
+
### 'Class rvalue used as lvalue' extension
1157
+
1158
+
1159
+
### 'Explicit specialization in non-namespace scope' extension
1160
+
1161
+
1162
+
### Checking for abstract class types
1163
+
1164
+
1165
+
### Support for P0960R3 - allow initializing aggregates from a parenthesized list of values
1166
+
1167
+
1168
+
### Overload resolution involving function templates
1169
+
1170
+
1171
+
### Migrating from `/await` to C++20 coroutines
1172
+
1156
1173
### `/permissive-` and C++20 Modules are on by default under `/std:c++latest`
1157
1174
1158
-
C++20 Modules is now supported, by default, under **`/std:c++latest`**. For more details regarding this change and scenarios where module and import are conditionally treated as keywords, see [Standard C++20 Modules support with MSVC in Visual Studio 2019 version 16.8](https://devblogs.microsoft.com/cppblog/standard-c20-modules-support-with-msvc-in-visual-studio-2019-version-16-8/).
1175
+
C++20 Modules support is on by default under **`/std:c++latest`**. For more information about this change, and the scenarios where **`module`** and **`import`** are conditionally treated as keywords, see [Standard C++20 Modules support with MSVC in Visual Studio 2019 version 16.8](https://devblogs.microsoft.com/cppblog/standard-c20-modules-support-with-msvc-in-visual-studio-2019-version-16-8/).
1159
1176
1160
-
As a prerequisite for Modules support, **`/permissive-`** is now enabled when **`/std:c++latest`** is specified. For more information, see [`/permissive-`](../build/reference/permissive-standards-conformance.md).
1161
-
For code that previously compiled under **`/std:c++latest`** and requires non-conformant compiler behaviors, /permissive may be specified to turn off strict conformance mode in the compiler and must appear after **`/std:c++latest`** in the command line argument list. However, specifying /permissive will result in an error if Modules usage is encountered.
1177
+
As a prerequisite for Modules support, **`permissive-`** is now enabled when **`/std:c++latest`** is specified. For more information, see [`/permissive-`](../build/reference/permissive-standards-conformance.md).
1162
1178
1163
-
error C1214: Modules conflict with non-standard behavior requested via '[option]'
1164
-
Where the most common values for [option] are:
1179
+
For code that previously compiled under **`/std:c++latest`** and requires non-conforming compiler behaviors, **`permissive`** may be specified to turn off strict conformance mode in the compiler. The compiler option must appear after **`/std:c++latest`** in the command-line argument list. However, **`permissive`** results in an error if Modules usage is encountered:
1165
1180
1166
-
Option Description
1167
-
/Zc:twoPhase- Two Phase name lookup (/Zc:twoPhase) is required for C++20 Modules and implied by /permissive-. See also /Zc:twoPhase documentation .
1168
-
/Zc:hiddenFriend- Enables standard hidden friend name lookup rules is required for C++20 Modules and implied by /permissive-.
1169
-
/Zc:preprocessor- Use of the conformant preprocessor (/Zc:preprocessor) is required for C++20 header unit usage and creation only. Named Modules do not require this option. See also /Zc:preprocessor documentation
1170
-
When using the std.* Modules which ship with Visual Studio the option /experimental:module is still required for their use as they are not yet standardized.
1181
+
> error C1214: Modules conflict with non-standard behavior requested via '*option*'
1171
1182
1172
-
Using /experimental:module also implies /Zc:twoPhase and /Zc:hiddenFriend. Previously code compiled with Modules could sometimes be compiled with /Zc:twoPhase- if the Module was only consumed, this behavior is no longer supported.
1173
-
### 'Class rvalue used as lvalue' extension
1174
-
### 'Class rvalue used as lvalue' extension
1175
-
### 'Class rvalue used as lvalue' extension
1176
-
### 'Class rvalue used as lvalue' extension
1177
-
### 'Class rvalue used as lvalue' extension
1178
-
### 'Class rvalue used as lvalue' extension
1183
+
The most common values for *option* are:
1184
+
1185
+
| Option | Description |
1186
+
|--|--|
1187
+
|[`/Zc:twoPhase-`](../build/reference/zc-twophase.md)| Two Phase name lookup is required for C++20 Modules and implied by **`permissive-`**. |
1188
+
|[`/Zc:hiddenFriend-`](../build/reference/zc-hiddenfriend.md)| Enables standard hidden friend name lookup rules. Required for C++20 Modules and implied by **`permissive-`**. |
1189
+
|[`/Zc:preprocessor-`](../build/reference/zc-preprocessor.md)| The conforming preprocessor is required for C++20 header unit usage and creation only. Named Modules don't require this option. |
1190
+
1191
+
The [`/experimental:module`](../build/reference/experimental-module.md) option is still required to use the *`std.*`* Modules that ship with Visual Studio, because they're not standardized yet.
1192
+
1193
+
The **`/experimental:module`** option also implies **`/Zc:twoPhase`** and **`/Zc:hiddenFriend`**. Previously, code compiled with Modules could sometimes be compiled with **`/Zc:twoPhase-`** if the Module was only consumed. This behavior is no longer supported.
1179
1194
1180
1195
## <aname="update_160"></a> Bug fixes and behavior changes in Visual Studio 2019
0 commit comments