Skip to content

Commit 5946cc5

Browse files
committed
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs-pr (branch live)
2 parents 12095b6 + 1aaae44 commit 5946cc5

File tree

10 files changed

+150
-51
lines changed

10 files changed

+150
-51
lines changed

docs/build/reference/zc-conformance.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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: 01/23/2021
4+
ms.date: 08/12/2021
55
helpviewer_keywords: ["/Zc compiler options [C++]", "-Zc compiler options [C++]", "Conformance compiler options", "Zc compiler options [C++]"]
66
---
77
# `/Zc` (Conformance)
@@ -30,6 +30,7 @@ Here are the **`/Zc`** compiler options:
3030
| [`/Zc:hiddenFriend`](zc-hiddenfriend.md) | Enforce Standard C++ hidden friend rules (implied by **`/permissive-`**) |
3131
| [`/Zc:implicitNoexcept`](zc-implicitnoexcept-implicit-exception-specifiers.md) | Enable implicit **`noexcept`** on required functions (on by default). |
3232
| [`/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). |
33+
| [`/Zc:lambda`](zc-lambda.md) | Enable new lambda processor for conformance-mode syntactic checks in generic lambdas. |
3334
| [`/Zc:noexceptTypes`](zc-noexcepttypes.md) | Enforce C++17 **`noexcept`** rules (on by default in C++17 or later). |
3435
| [`/Zc:preprocessor`](zc-preprocessor.md) | Use the new conforming preprocessor (off by default, except in C11/C17). |
3536
| [`/Zc:referenceBinding`](zc-referencebinding-enforce-reference-binding-rules.md) | A UDT temporary won't bind to a non-const lvalue reference (off by default). |

docs/build/reference/zc-cplusplus.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
---
22
description: "Learn more about: /Zc:__cplusplus (Enable updated __cplusplus macro)"
33
title: "/Zc:__cplusplus (Enable updated __cplusplus macro)"
4-
ms.date: "05/16/2019"
4+
ms.date: 08/11/2021
55
f1_keywords: ["/Zc:__cplusplus"]
66
helpviewer_keywords: ["-Zc:__cplusplus compiler option (C++)", "__cplusplus macro (C++)"]
77
---
8-
# /Zc:__cplusplus (Enable updated __cplusplus macro)
8+
# `/Zc:__cplusplus` (Enable updated `__cplusplus` macro)
99

10-
The **/Zc:__cplusplus** compiler option enables the **\_\_cplusplus** preprocessor macro to report an updated value for recent C++ language standards support. By default, Visual Studio always returns the value "199711L" for the **\_\_cplusplus** preprocessor macro.
10+
The **`/Zc:__cplusplus`** compiler option enables the `__cplusplus` preprocessor macro to report an updated value for recent C++ language standards support. By default, Visual Studio always returns the value `199711L` for the `__cplusplus` preprocessor macro.
1111

1212
## Syntax
1313

14-
> **/Zc:__cplusplus**[**-**]
14+
> **`/Zc:__cplusplus`**[**`-`**]
1515
1616
## Remarks
1717

18-
The **\_\_cplusplus** preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because lots of existing code appears to depend on the value of this macro matching "199711L", the compiler does not change the value of the macro unless you explicitly opt-in by using the **/Zc:__cplusplus** compiler option. The **/Zc:__cplusplus** option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if **/Zc:__cplusplus-** is specified, Visual Studio returns the value "199711L" for the **\_\_cplusplus** preprocessor macro. The [/permissive-](permissive-standards-conformance.md) option does not enable **/Zc:__cplusplus**.
18+
The `__cplusplus` preprocessor macro is commonly used to report support for a particular version of the C++ standard. Because a lot of existing code appears to depend on the value of this macro matching `199711L`, the compiler doesn't change the value of the macro unless you explicitly opt in by using the **`/Zc:__cplusplus`** compiler option. The **`/Zc:__cplusplus`** option is available starting in Visual Studio 2017 version 15.7, and is off by default. In earlier versions of Visual Studio, and by default, or if **`/Zc:__cplusplus-`** is specified, Visual Studio returns the value `199711L` for the `__cplusplus` preprocessor macro. The [`/permissive-`](permissive-standards-conformance.md) option doesn't enable **`/Zc:__cplusplus`**.
1919

20-
When the **/Zc:__cplusplus** option is enabled, the value reported by the **\_\_cplusplus** macro depends on the [/std](std-specify-language-standard-version.md) version switch setting. This table shows the possible values for the macro:
20+
When the **`/Zc:__cplusplus`** option is enabled, the value reported by the `__cplusplus` macro depends on the [`/std`](std-specify-language-standard-version.md) version option setting. This table shows the possible values for the macro:
2121

22-
|/Zc:__cplusplus switch|/std:c++ switch|__cplusplus value|
23-
|-|-|-|
24-
Zc:__cplusplus|/std:c++14 (default)|201402L
25-
Zc:__cplusplus|/std:c++17|201703L
26-
Zc:__cplusplus|/std:c++latest|201704L
27-
Zc:__cplusplus- (disabled)|Any value|199711L
28-
Not specified|Any value|199711L
22+
| `/Zc:__cplusplus` option | `/std` option | `__cplusplus` value |
23+
|--|--|--|
24+
| `Zc:__cplusplus` | `/std:c++14` (default) | `201402L` |
25+
| `Zc:__cplusplus` | `/std:c++17` | `201703L` |
26+
| `Zc:__cplusplus` | `/std:c++20` | `202002L` |
27+
| `Zc:__cplusplus` | `/std:c++latest` | see text |
28+
| `Zc:__cplusplus-` (disabled) | Any value | `199711L` |
29+
| Not specified | Any value | `199711L` |
2930

30-
The compiler does not support standards switches for C++98, C++03, or C++11.
31+
The compiler doesn't support standards options for C++98, C++03, or C++11. The **`/std:c++20`** option is available starting in Visual Studio 2019 version 16.11. The value of `__cplusplus` with the **`/std:c++latest`** option depends on the version of Visual Studio. It's always at least one higher than the highest supported `__cplusplus` standard value supported by your version of Visual Studio.
3132

32-
For finer-grained detection of changes to the compiler toolset, use the [_MSC_VER](../../preprocessor/predefined-macros.md) predefined macro. The value of this built-in macro is incremented for every toolset update in Visual Studio 2017 and later versions. The [_MSVC_LANG](../../preprocessor/predefined-macros.md) predefined macro reports the standard version whether the **/Zc:__cplusplus** option is enabled or disabled. When **/Zc:__cplusplus** is enabled, `__cplusplus == _MSVC_LANG`.
33+
For finer-grained detection of changes to the compiler toolset, use the [`_MSC_VER`](../../preprocessor/predefined-macros.md) predefined macro. The value of this built-in macro is incremented for every toolset update in Visual Studio 2017 and later versions. The [`_MSVC_LANG`](../../preprocessor/predefined-macros.md) predefined macro reports the standard version whether the **`/Zc:__cplusplus`** option is enabled or disabled. When **`/Zc:__cplusplus`** is enabled, `__cplusplus` has the same value as `_MSVC_LANG`.
3334

3435
### To set this compiler option in Visual Studio
3536

3637
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).
3738

3839
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
3940

40-
1. Add **/Zc:__cplusplus** or **/Zc:__cplusplus-** to the **Additional options:** pane.
41+
1. Add **`/Zc:__cplusplus`** or **`/Zc:__cplusplus-`** to the **Additional options:** pane.
4142

4243
## See also
4344

44-
- [/Zc (Conformance)](zc-conformance.md)
45-
- [/std (Specify language standard version)](std-specify-language-standard-version.md)
46-
- [Predefined macros](../../preprocessor/predefined-macros.md)
45+
[`/Zc` (Conformance)](zc-conformance.md)\
46+
[`/std` (Specify language standard version)](std-specify-language-standard-version.md)\
47+
[Predefined macros](../../preprocessor/predefined-macros.md)

docs/build/reference/zc-lambda.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
description: "Learn more about: /Zc:lambda (Enable updated lambda processor)"
3+
title: "/Zc:lambda (Enable updated lambda processor)"
4+
ms.date: 08/11/2021
5+
f1_keywords: ["/Zc:lambda"]
6+
helpviewer_keywords: ["-Zc:lambda compiler option (C++)", "/Zc:lambda compiler option (C++)"]
7+
---
8+
# `/Zc:lambda` (Enable updated lambda processor)
9+
10+
The **`/Zc:lambda`** compiler option enables conforming lambda grammar and processing support.
11+
12+
## Syntax
13+
14+
> **`/Zc:lambda`**[**`-`**]
15+
16+
## Remarks
17+
18+
The **`/Zc:lambda`** compiler option enables the conforming lambda processor. It parses and implements lambda code according to the C++ standard. This option is off by default, which uses the legacy lambda processor. Use this option to enable conformance-mode syntax checks of generic lambdas when you use the default [`/std:c++14`](std-specify-language-standard-version.md) or the [`/std:c++17`](std-specify-language-standard-version.md) compiler options.
19+
20+
**`/Zc:lambda`** is automatically enabled by the [`/std:c++20`](std-specify-language-standard-version.md), [`/std:c++latest`](std-specify-language-standard-version.md), and [`/experimental:module`](experimental-module.md) options. You can disable it explicitly by using **`/Zc:lambda-`**. The [`/permissive-`](permissive-standards-conformance.md) option doesn't enable **`/Zc:lambda`**.
21+
22+
The **`/Zc:lambda`** option is available starting in Visual Studio 2019 version 16.8. It's available as **`/experimental:newLambdaProcessor`** starting in Visual Studio 2019 version 16.3, but this spelling is now deprecated.
23+
24+
The legacy lambda processor has limitations when it parses and compiles lambdas. For example, this conforming code compiles correctly under **`/Zc:lambda`**, but reports errors under **`/Zc:lambda-`**:
25+
26+
```cpp
27+
void f1()
28+
{
29+
constexpr auto c_value = 1;
30+
auto func = []()
31+
{
32+
return c_value; // error C3493: 'c_value' cannot be implicitly captured
33+
// because no default capture mode has been specified
34+
};
35+
func(); // error C2064: term does not evaluate to a function taking 0 arguments
36+
}
37+
```
38+
39+
The legacy lambda processor compiles this code without warnings, but the new lambda processor produces error C2760:
40+
41+
```cpp
42+
void f2() {
43+
auto a = [](auto arg) {
44+
decltype(arg)::Type t; // C2760 syntax error: unexpected token 'identifier', expected ';'
45+
};
46+
}
47+
```
48+
49+
This example shows the correct syntax, now enforced by the compiler under **`/Zc:lambda`**:
50+
51+
```cpp
52+
void f3() {
53+
auto a = [](auto arg) {
54+
typename decltype(arg)::Type t;
55+
};
56+
}
57+
```
58+
59+
### To set this compiler option in Visual Studio
60+
61+
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).
62+
63+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
64+
65+
1. Add **`/Zc:lambda`** or **`/Zc:lambda-`** to the **Additional options:** pane.
66+
67+
## See also
68+
69+
[`/Zc` (Conformance)](zc-conformance.md)\
70+
[`/std` (Specify language standard version)](std-specify-language-standard-version.md)

docs/build/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,9 @@
773773
href: ../build/reference/zc-implicitnoexcept-implicit-exception-specifiers.md
774774
- name: "/Zc:inline (Remove unreferenced COMDAT)"
775775
href: ../build/reference/zc-inline-remove-unreferenced-comdat.md
776+
- name: "/Zc:lambda (Enable updated lambda processor)"
777+
href: ../build/reference/zc-lambda.md
778+
- name: "/Zc:preprocessor (Enable preprocessor conformance mode)"
776779
- name: "/Zc:noexceptTypes (C++17 noexcept rules)"
777780
href: ../build/reference/zc-noexcepttypes.md
778781
- name: "/Zc:preprocessor (Enable preprocessor conformance mode)"

docs/cpp/program-and-linkage-cpp.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
description: "Learn more about: Translation units and linkage"
33
title: "Translation units and linkage (C++)"
4-
ms.date: "12/11/2019"
4+
ms.date: 08/12/2021
55
ms.assetid: a6493ba0-24e2-4c89-956e-9da1dea660cb
66
---
77
# Translation units and linkage
88

9-
In a C++ program, a *symbol*, for example a variable or function name, can be declared any number of times within its scope, but it can only be defined once. This rule is the "One Definition Rule" (ODR). A *declaration* introduces (or re-introduces) a name into the program. A *definition* introduces a name. If the name represents a variable, a definition explicitly initializes it. A *function definition* consists of the signature plus the function body. A class definition consists of the class name followed by a block that lists all the class members. (The bodies of member functions may optionally be defined separately in another file.)
9+
In a C++ program, a *symbol*, for example a variable or function name, can be declared any number of times within its scope. However, it can only be defined once. This rule is the "One Definition Rule" (ODR). A *declaration* introduces (or reintroduces) a name into the program, along with enough information to later associate the name with a definition. A *definition* introduces a name and provides all the information needed to create it. If the name represents a variable, a definition explicitly creates storage and initializes it. A *function definition* consists of the signature plus the function body. A class definition consists of the class name followed by a block that lists all the class members. (The bodies of member functions may optionally be defined separately in another file.)
1010

1111
The following example shows some declarations:
1212

@@ -27,35 +27,35 @@ public:
2727
};
2828
```
2929

30-
A program consists of one or more *translation units*. A translation unit consists of an implementation file and all the headers that it includes directly or indirectly. Implementation files typically have a file extension of *cpp* or *cxx*. Header files typically have an extension of *h* or *hpp*. Each translation unit is compiled independently by the compiler. After the compilation is complete, the linker merges the compiled translation units into a single *program*. Violations of the ODR rule typically show up as linker errors. Linker errors occur when the same name has two different definitions in different translation units.
30+
A program consists of one or more *translation units*. A translation unit consists of an implementation file and all the headers that it includes directly or indirectly. Implementation files typically have a file extension of *`.cpp`* or *`.cxx`*. Header files typically have an extension of *`.h`* or *`.hpp`*. Each translation unit is compiled independently by the compiler. After the compilation is complete, the linker merges the compiled translation units into a single *program*. Violations of the ODR rule typically show up as linker errors. Linker errors occur when the same name has two different definitions in different translation units.
3131

32-
In general, the best way to make a variable visible across multiple files is to put it in a header file. Then add an #include directive in every *cpp* file that requires the declaration. By adding *include guards* around the header contents, you ensure that the names it declares are only defined once.
32+
In general, the best way to make a variable visible across multiple files is to put it in a header file. Then add an #include directive in every *`.cpp`* file that requires the declaration. By adding *include guards* around the header contents, you ensure that the names it declares are only defined once.
3333

3434
In C++20, [modules](modules-cpp.md) are introduced as an improved alternative to header files.
3535

36-
In some cases it may be necessary to declare a global variable or class in a *cpp* file. In those cases, you need a way to tell the compiler and linker what kind of *linkage* the name has. The type of linkage specifies whether the name of the object applies just to the one file, or to all files. The concept of linkage applies only to global names. The concept of linkage does not apply to names that are declared within a scope. A scope is specified by a set of enclosing braces such as in function or class definitions.
36+
In some cases, it may be necessary to declare a global variable or class in a *`.cpp`* file. In those cases, you need a way to tell the compiler and linker what kind of *linkage* the name has. The type of linkage specifies whether the name of the object applies just to the one file, or to all files. The concept of linkage applies only to global names. The concept of linkage doesn't apply to names that are declared within a scope. A scope is specified by a set of enclosing braces such as in function or class definitions.
3737

3838
## External vs. internal linkage
3939

40-
A *free function* is a function that is defined at global or namespace scope. Non-const global variables and free functions by default have *external linkage*; they are visible from any translation unit in the program. Therefore, no other global object can have that name. A symbol with *internal linkage* or *no linkage* is visible only within the translation unit in which it is declared. When a name has internal linkage, the same name may exist in another translation unit. Variables declared within class definitions or function bodies have no linkage.
40+
A *free function* is a function that is defined at global or namespace scope. Non-const global variables and free functions by default have *external linkage*; they're visible from any translation unit in the program. No other global object can have that name. A symbol with *internal linkage* or *no linkage* is visible only within the translation unit in which it's declared. When a name has internal linkage, the same name may exist in another translation unit. Variables declared within class definitions or function bodies have no linkage.
4141

42-
You can force a global name to have internal linkage by explicitly declaring it as **`static`**. This limits its visibility to the same translation unit in which it is declared. In this context, **`static`** means something different than when applied to local variables.
42+
You can force a global name to have internal linkage by explicitly declaring it as **`static`**. This keyword limits its visibility to the same translation unit in which it's declared. In this context, **`static`** means something different than when applied to local variables.
4343

4444
The following objects have internal linkage by default:
4545

46-
- const objects
47-
- constexpr objects
48-
- typedefs
49-
- static objects in namespace scope
46+
- **`const`** objects
47+
- **`constexpr`** objects
48+
- **`typedef`** objects
49+
- **`static`** objects in namespace scope
5050

51-
To give a const object external linkage, declare it as **`extern`** and assign it a value:
51+
To give a **`const`** object external linkage, declare it as **`extern`** and assign it a value:
5252

5353
```cpp
5454
extern const int value = 42;
5555
```
5656

57-
See [extern](extern-cpp.md) for more information.
57+
For more information, see [`extern`](extern-cpp.md).
5858

5959
## See also
6060

61-
[Basic Concepts](../cpp/basic-concepts-cpp.md)
61+
[Basic concepts](../cpp/basic-concepts-cpp.md)

docs/error-messages/compiler-errors-2/compiler-error-c2760.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
22
description: "Learn more about: Compiler Error C2760"
33
title: "Compiler Error C2760"
4-
ms.date: "11/04/2016"
4+
ms.date: 08/12/2021
55
f1_keywords: ["C2760"]
66
helpviewer_keywords: ["C2760"]
77
ms.assetid: 585757fd-d519-43f3-94e5-50316ac8b90b
88
---
99
# Compiler Error C2760
1010

11-
> syntax error : expected '*name1*' not '*name2*'
11+
> syntax error : expected '*name1*' not '*name2*'\
12+
> syntax error : unexpected token '*token1*', expected '*token2*'\
13+
> syntax error: '*token1*' was unexpected here; expected '*token2*'
1214
1315
## Remarks
1416

@@ -29,3 +31,23 @@ void f(B* pb) {
2931
D* pd3 = static_cast<D*=(pb); // C2760
3032
}
3133
```
34+
35+
The new lambda processor available under [`/std:c++20`](../../build/reference/std-specify-language-standard-version.md) or later, or under [`/Zc:lambda`](../../build/reference/zc-lambda.md), enables some new conformance-mode syntactic checks in generic lambdas. The legacy lambda processor compiles this code without warnings, but the new lambda processor produces error C2760:
36+
37+
```cpp
38+
void f() {
39+
auto a = [](auto arg) {
40+
decltype(arg)::Type t; // C2760 syntax error: unexpected token 'identifier', expected ';'
41+
};
42+
}
43+
```
44+
45+
This example shows the correct syntax, now enforced by the compiler, which works in all **`/std`** modes:
46+
47+
```cpp
48+
void f() {
49+
auto a = [](auto arg) {
50+
typename decltype(arg)::Type t;
51+
};
52+
}
53+
```

0 commit comments

Comments
 (0)