Skip to content

Commit 74e58be

Browse files
authored
Merge pull request #3374 from MicrosoftDocs/master
1/25/2021 AM Publish
2 parents a26a66a + 7dff481 commit 74e58be

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

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
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
---
22
title: "/Zc (Conformance)"
33
description: "The /Zc conformance compiler options enable or disable support for conforming or backward-compatible behavior."
4-
ms.date: 09/10/2020
4+
ms.date: 01/23/2021
55
helpviewer_keywords: ["/Zc compiler options [C++]", "-Zc compiler options [C++]", "Conformance compiler options", "Zc compiler options [C++]"]
6-
ms.assetid: db1cc175-6e93-4a2e-9396-c3725d2d8f71
76
---
87
# `/Zc` (Conformance)
98

109
You can use the **`/Zc`** compiler options to specify standard or Microsoft-specific compiler behavior.
1110

1211
## Syntax
1312

14-
> **`/Zc:`**_option_{,_option_}
13+
> **`/Zc:`**_option_{,_option_ ...}
14+
15+
You may set multiple **`/Zc`** options separated by commas in a single **`/Zc`** compiler option. If a **`/Zc`** option is enabled and disabled in the same command, the option that appears last is used.
1516

1617
## Remarks
1718

18-
When Visual Studio has implemented an extension to C or C++ that is not compatible with the standard, you can use a **`/Zc`** conformance option to specify standard-conforming or Microsoft-specific behavior. For some options, the Microsoft-specific behavior is the default, to prevent large-scale breaking changes to existing code. In other cases, the default is the standard behavior, where improvements in security, performance, or compatibility outweigh the costs of breaking changes. The default setting of each conformance option may change in newer versions of Visual Studio. For more information about each conformance option, see the topic for the specific option. The [`/permissive-`](permissive-standards-conformance.md) compiler option implicitly sets the conformance options that are not set by default to their conformant setting.
19+
When Visual Studio has implemented an extension to C or C++ that is incompatible with the standard, you can use a **`/Zc`** conformance option to specify standard-conforming or Microsoft-specific behavior. For some options, the Microsoft-specific behavior is the default, to prevent large-scale breaking changes to existing code. In other cases, the default is the standard behavior, where improvements in security, performance, or compatibility outweigh the costs of breaking changes. The default setting of each conformance option may change in newer versions of Visual Studio. For more information about each conformance option, see the article for the specific option. The [`/permissive-`](permissive-standards-conformance.md) compiler option implicitly sets the conformance options that aren't set by default to their conforming settings.
1920

20-
These are the **`/Zc`** compiler options:
21+
Here are the **`/Zc`** compiler options:
2122

2223
| Option | Behavior |
2324
|--|--|
@@ -26,11 +27,12 @@ These are the **`/Zc`** compiler options:
2627
| [`/Zc:__cplusplus`](zc-cplusplus.md) | Enable the `__cplusplus` macro to report the supported standard (off by default). |
2728
| [`/Zc:externConstexpr`](zc-externconstexpr.md) | Enable external linkage for **`constexpr`** variables (off by default). |
2829
| [`/Zc:forScope`](zc-forscope-force-conformance-in-for-loop-scope.md) | Enforce Standard C++ **`for`** scoping rules (on by default). |
30+
| [`/Zc:hiddenFriend`](zc-hiddenfriend.md) | Enforce Standard C++ hidden friend rules (implied by **`/permissive-`**) |
2931
| [`/Zc:implicitNoexcept`](zc-implicitnoexcept-implicit-exception-specifiers.md) | Enable implicit **`noexcept`** on required functions (on by default). |
30-
| [`/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). |
32+
| [`/Zc:inline`](zc-inline-remove-unreferenced-comdat.md) | Remove unreferenced functions or data if they're COMDAT or have internal linkage only (off by default). |
3133
| [`/Zc:noexceptTypes`](zc-noexcepttypes.md) | Enforce C++17 **`noexcept`** rules (on by default in C++17 or later). |
3234
| [`/Zc:preprocessor`](zc-preprocessor.md) | Use the new conforming preprocessor (off by default, except in C11/C17). |
33-
| [`/Zc:referenceBinding`](zc-referencebinding-enforce-reference-binding-rules.md) | A UDT temporary will not bind to an non-const lvalue reference (off by default). |
35+
| [`/Zc:referenceBinding`](zc-referencebinding-enforce-reference-binding-rules.md) | A UDT temporary won't bind to a non-const lvalue reference (off by default). |
3436
| [`/Zc:rvalueCast`](zc-rvaluecast-enforce-type-conversion-rules.md) | Enforce Standard C++ explicit type conversion rules (off by default). |
3537
| [`/Zc:sizedDealloc`](zc-sizeddealloc-enable-global-sized-dealloc-functions.md) | Enable C++14 global sized deallocation functions (on by default). |
3638
| [`/Zc:strictStrings`](zc-strictstrings-disable-string-literal-type-conversion.md) | Disable string-literal to `char*` or `wchar_t*` conversion (off by default). |
@@ -41,9 +43,9 @@ These are the **`/Zc`** compiler options:
4143
| [`/Zc:twoPhase`](zc-twophase.md) | Use non-conforming template parsing behavior (conforming by default). |
4244
| [`/Zc:wchar_t`](zc-wchar-t-wchar-t-is-native-type.md) | **`wchar_t`** is a native type, not a typedef (on by default). |
4345

44-
For more information about conformance issues in Visual C++, see [Nonstandard Behavior](../../cpp/nonstandard-behavior.md).
46+
For more information about conformance issues in MSVC, see [Nonstandard behavior](../../cpp/nonstandard-behavior.md).
4547

4648
## See also
4749

48-
[MSVC Compiler Options](compiler-options.md)<br/>
49-
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)
50+
[MSVC compiler options](compiler-options.md)<br/>
51+
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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: 01/23/2021
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.
11+
12+
## Syntax
13+
14+
> **`/Zc:hiddenFriend`**\[**`-`**]
15+
16+
## Remarks
17+
18+
The **`/Zc:hiddenFriend`** option enables a subset of the [`/permissive-`](permissive-standards-conformance.md) option behavior. It tells the compiler to conform to the standard for hidden friends. The compiler only includes hidden friends in [argument-dependent lookup](../../cpp/argument-dependent-name-koenig-lookup-on-functions.md) (ADL) for explicit instances or template parameters of the enclosing class type. The restriction allows you to use hidden friends to keep operations on a type from applying to implicit conversions. 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 doesn't remove hidden friend declarations as candidates for overload resolution everywhere it should. This legacy behavior can slow the compiler down by including the hidden friend functions as possible candidates in more contexts.
21+
22+
Standard C++ hidden friend behavior is enabled by default under **`/permissive-`**. 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.
23+
24+
The **`/Zc:hiddenFriend`** option is available starting in Visual Studio 2019 version 16.4.
25+
26+
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).
27+
28+
### To set this compiler option in the Visual Studio development environment
29+
30+
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).
31+
32+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
33+
34+
1. Modify the **Additional Options** property to include *`/Zc:hiddenFriend`* or *`/Zc:hiddenFriend-`* and then choose **OK**.
35+
36+
## See also
37+
38+
[`/Zc` (Conformance)](zc-conformance.md)\
39+
[`/permissive-`](permissive-standards-conformance.md)

docs/build/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@
761761
href: ../build/reference/zc-externconstexpr.md
762762
- name: "/Zc:forScope (Force conformance in for loop scope)"
763763
href: ../build/reference/zc-forscope-force-conformance-in-for-loop-scope.md
764+
- name: "/Zc:hiddenFriend (Enforce Standard C++ hidden friend rules)"
765+
href: ../build/reference/zc-hiddenfriend.md
764766
- name: "/Zc:implicitNoexcept (Implicit exception specifiers)"
765767
href: ../build/reference/zc-implicitnoexcept-implicit-exception-specifiers.md
766768
- 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)