Skip to content

Commit b14faca

Browse files
author
Colin Robertson
committed
more partial work
1 parent 836e5ac commit b14faca

3 files changed

Lines changed: 114 additions & 18 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: "/Zc:hiddenFriend (Enforce hidden friend rules)"
3+
description: "Learn about the Microsoft C++ /Zc:hiddenFriend compiler option for conforming or relaxed hidden friend compatibility."
4+
ms.date: "06/04/2020"
5+
f1_keywords: ["/Zc:hiddenFriend"]
6+
helpviewer_keywords: ["/Zc:hiddenFriend", "Zc:hiddenFriend", "-Zc:hiddenFriend"]
7+
ms.assetid: 1cbf7e3c-0f82-4f91-84dd-612bcf26d2c6
8+
---
9+
# /Zc:hiddenFriend (Enforce hidden friend rules)
10+
11+
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+
void f() throw(); // equivalent to void f() noexcept;
35+
void f() { } // 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).
72+
73+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
74+
75+
1. Modify the **Additional Options** property to include *`/Zc:hiddenFriend`* or *`/Zc:hiddenFriend-`* and then choose **OK**.
76+
77+
## See also
78+
79+
[**`/Zc`** (Conformance)](zc-conformance.md)\
80+
[noexcept](../../cpp/noexcept-cpp.md)\
81+
[Exception specifications (throw)](../../cpp/exception-specifications-throw-cpp.md)

docs/build/reference/zc-noexcepttypes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ For more information about conformance issues in Visual C++, see [Nonstandard Be
7272

7373
## See also
7474

75-
[**`/Zc`** (Conformance)](zc-conformance.md)\
75+
[`/Zc` (Conformance)](zc-conformance.md)\
7676
[noexcept](../../cpp/noexcept-cpp.md)\
7777
[Exception specifications (throw)](../../cpp/exception-specifications-throw-cpp.md)

docs/overview/cpp-conformance-improvements.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,29 +1153,44 @@ void f() {
11531153
<!-- TODO 16.8 -->
11541154
## <a name="improvements_168"></a> Conformance improvements in Visual Studio 2019 version 16.8
11551155

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+
11561173
### `/permissive-` and C++20 Modules are on by default under `/std:c++latest`
11571174

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/).
11591176

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).
11621178

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:
11651180

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*'
11711182

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.
11791194

11801195
## <a name="update_160"></a> Bug fixes and behavior changes in Visual Studio 2019
11811196

0 commit comments

Comments
 (0)