Skip to content

Commit 1bc3a23

Browse files
author
Colin Robertson
committed
Add /Zc:hiddenFriend docs
1 parent 308253f commit 1bc3a23

5 files changed

Lines changed: 48 additions & 2 deletions

File tree

docs/build/reference/permissive-standards-conformance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ void g() {
129129
}
130130
```
131131

132+
You can enable the hidden friend name lookup rules independently of **`/permissive`** by using [`/Zc:hiddenFriend`](./zc-hiddenfriend.md). If you want legacy behavior for hidden friend name lookup, but otherwise want **`/permissive-`** behavior, use the **`/Zc:hiddenFriend-`** option.
133+
132134
#### Use scoped enums in array bounds
133135

134136
```cpp

docs/build/reference/zc-conformance.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ These are the **`/Zc`** compiler options:
2626
| [`/Zc__cplusplus`](zc-cplusplus.md) | Enable the `__cplusplus` macro to report the supported standard (off by default). |
2727
| [`/Zc:externConstexpr`](zc-externconstexpr.md) | Enable external linkage for **`constexpr`** variables (off by default). |
2828
| [`/Zc:forScope`](zc-forscope-force-conformance-in-for-loop-scope.md) | Enforce Standard C++ **`for`** scoping rules (on by default). |
29-
| [`/ZcimplicitNoexcept`](zc-implicitnoexcept-implicit-exception-specifiers.md) | Enable implicit **`noexcept`** on required functions (on by default). |
29+
| [`/Zc:hiddenFriend`](zc-hiddenfriend.md) | Enforce Standard C++ hidden friend rules (implied by /permissive-) |
30+
| [`/Zc:implicitNoexcept`](zc-implicitnoexcept-implicit-exception-specifiers.md) | Enable implicit **`noexcept`** on required functions (on by default). |
3031
| [`/Zc:inline`](zc-inline-remove-unreferenced-comdat.md) | Remove unreferenced function or data if it is COMDAT or has internal linkage only (off by default). |
3132
| [`/Zc:noexceptTypes`](zc-noexcepttypes.md) | Enforce C++17 **`noexcept`** rules (on by default in C++17 or later). |
3233
| [`/Zc:preprocessor`](zc-preprocessor.md) | Use the new conforming preprocessor (off by default, except in C11/C17). |
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "/Zc:hiddenFriend (Enforce Standard C++ hidden friend rules)"
3+
description: "Learn about the Microsoft C++ /Zc:hiddenFriend compiler option for conforming or relaxed hidden friend compatibility."
4+
ms.date: 11/11/2020
5+
f1_keywords: ["/Zc:hiddenFriend"]
6+
helpviewer_keywords: ["/Zc:hiddenFriend", "Zc:hiddenFriend", "-Zc:hiddenFriend"]
7+
---
8+
# /Zc:hiddenFriend (Enforce Standard C++ hidden friend rules)
9+
10+
Specifies the compiler conforms to the C++ standard treatment of hidden friend functions or function templates. The C++20 standard limits the scope visibility of hidden friends to the enclosing class or class template. The compiler only includes hidden friends in argument-dependent lookup (ADL) for explicit instances of the enclosing class type.
11+
12+
## Syntax
13+
14+
> **`/Zc:hiddenFriend`**\[**`-`**]
15+
16+
## Remarks
17+
18+
The **`/Zc:hiddenFriend`** option tells the compiler to conform to the standard and limit the scope visibility of hidden friends to the enclosing class or class template. This option can improve build speed in code that can't otherwise use [`/permissive-`](permissive-standards-conformance.md).
19+
20+
A *hidden friend* is a **`friend`** function or function template declared only within a class or class template definition. By default, the Microsoft C++ compiler makes such declarations visible in the enclosing namespace. That visibility means the hidden friend is available for both ordinary unqualified lookup and qualified lookup during overload resolution. This legacy behavior can slow the compiler down, by introducing additional candidates for overload resolution.
21+
22+
The C++20 standard clarified that a hidden friend can't appear to have a visible declaration at namespace scope. The hidden friend doesn't participate in overload resolution in all contexts that use the enclosing namespace. The restriction allows you to use hidden friends to keep operations on a type from applying to implicit conversions. Hidden friends can only participate in ADL on explicit instances of the enclosing class type.
23+
24+
Standard C++ hidden friend behavior is enabled by default under [`/permissive-`](permissive-standards-conformance.md). To specify legacy hidden friend behavior when the **`/permissive-`** option is specified, use **`/Zc:hiddenFriend-`**. Use of C++20 Modules requires standard hidden friend behavior.
25+
26+
The **`/Zc:hiddenFriend`** option is available starting in Visual Studio 2019 version 16.4.
27+
28+
For examples of compiler behavior when you specify **`/Zc:hiddenFriend`**, see [Hidden friend name lookup rules](./permissive-standards-conformance.md#hidden-friend-name-lookup-rules).
29+
30+
### To set this compiler option in the Visual Studio development environment
31+
32+
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).
33+
34+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
35+
36+
1. Modify the **Additional Options** property to include *`/Zc:hiddenFriend`* or *`/Zc:hiddenFriend-`* and then choose **OK**.
37+
38+
## See also
39+
40+
[**`/Zc`** (Conformance)](zc-conformance.md)\
41+
[`/permissive-`](permissive-standards-conformance.md)

docs/build/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@
748748
href: ../build/reference/zc-externconstexpr.md
749749
- name: "/Zc:forScope (Force conformance in for loop scope)"
750750
href: ../build/reference/zc-forscope-force-conformance-in-for-loop-scope.md
751+
- name: "/Zc:hiddenFriend (Enforce Standard C++ hidden friend rules)"
752+
href: ../build/reference/zc-hiddenfriend.md
751753
- name: "/Zc:implicitNoexcept (Implicit exception specifiers)"
752754
href: ../build/reference/zc-implicitnoexcept-implicit-exception-specifiers.md
753755
- name: "/Zc:inline (Remove unreferenced COMDAT)"

docs/overview/cpp-conformance-improvements.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ The most common values for *option* are:
14751475
| Option | Description |
14761476
|--|--|
14771477
| **`/Zc:twoPhase-`** | Two Phase name lookup is required for C++20 Modules and implied by **`permissive-`**. |
1478-
| **`/Zc:hiddenFriend-`** | Enables standard hidden friend name lookup rules. Required for C++20 Modules and implied by **`permissive-`**. |
1478+
| **`/Zc:hiddenFriend-`** | Standard hidden friend name lookup rules are required for C++20 Modules and implied by **`permissive-`**. |
14791479
| **`/Zc:preprocessor-`** | The conforming preprocessor is required for C++20 header unit usage and creation only. Named Modules don't require this option. |
14801480
14811481
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.

0 commit comments

Comments
 (0)