Skip to content

Repo sync for protected CLA branch #4275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
67ac39f
updating asan runtime documentation for iat_overwrite option
zacklj89 Sep 22, 2022
ec88153
updating cross-site links
zacklj89 Sep 22, 2022
9304119
update motivation and protect explanation
zacklj89 Sep 23, 2022
755972d
Potentially clear protect up
zacklj89 Sep 23, 2022
7674b7d
Update styles, make the grammar checker happy
colin-home Nov 3, 2022
bc639e2
Update owner of Latest VC Redist page
colin-home Nov 7, 2022
7376b7c
Merge pull request #4661 from corob-msft/redist-owner-change
prmerger-automator[bot] Nov 7, 2022
4036f9d
add table entries
Nov 7, 2022
9f42987
Merge pull request #4662 from TylerMSFT/istream
prmerger-automator[bot] Nov 7, 2022
2c215f6
add range adaptor example for wistream_view
Nov 7, 2022
9180fe1
spacing
Nov 7, 2022
a96d778
Merge pull request #4663 from TylerMSFT/wistream
prmerger-automator[bot] Nov 7, 2022
c003120
PoliCheck updates
damabe Nov 8, 2022
5e3d947
17.4 Release updates
colin-home Nov 8, 2022
f53859e
Merge pull request #4664 from damabe/vdamabe-policheck2
prmerger-automator[bot] Nov 8, 2022
8fc0c8f
Break up problem table.
colin-home Nov 8, 2022
da06c1c
Merge pull request #4537 from zacklj89/dev/zajohnson/iat-overwrite-doc
prmerger-automator[bot] Nov 8, 2022
44aded5
Merge pull request #4666 from MicrosoftDocs/main
huypub Nov 8, 2022
804abd5
Update TOC for new Zc articles
colin-home Nov 8, 2022
e01e745
Update what's new 17.4 section
colin-home Nov 8, 2022
7fee54a
Renderer is broken by pipe in code?
colin-home Nov 8, 2022
59d8ae2
Undo "fix" for pipe
colin-home Nov 8, 2022
742170c
Merge pull request #4665 from corob-msft/release-17.4-1
JamesJBarnett Nov 8, 2022
e0e2b81
Merge pull request #4667 from MicrosoftDocs/main
colin-home Nov 8, 2022
0cb7e77
Merging changes synced from https://github.com/MicrosoftDocs/cpp-docs…
opbld15 Nov 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Compiler options listed alphabetically"
description: "Reference listing in alphabetical order of the Microsoft C/C++ compiler command-line options."
ms.date: 04/15/2022
ms.date: 11/07/2022
helpviewer_keywords: ["compiler options, C++"]
---
# Compiler options listed alphabetically
Expand Down Expand Up @@ -212,9 +212,11 @@ This table contains an alphabetical list of compiler options. For a list of comp
| [`/Z7`](z7-zi-zi-debug-information-format.md) | Generates C 7.0-compatible debugging information. |
| [`/Za`](za-ze-disable-language-extensions.md) | Disables some C89 language extensions in C code. |
| [`/Zc:__cplusplus[-]`](zc-cplusplus.md) | Enable the `__cplusplus` macro to report the supported standard (off by default). |
| [`/Zc:__STDC__`](zc-stdc.md) | Enable the `__STDC__` macro to report the C standard is supported (off by default). |
| [`/Zc:alignedNew[-]`](zc-alignednew.md) | Enable C++17 over-aligned dynamic allocation (on by default in C++17). |
| [`/Zc:auto[-]`](zc-auto-deduce-variable-type.md) | Enforce the new Standard C++ meaning for **`auto`** (on by default). |
| [`/Zc:char8_t[-]`](zc-char8-t.md) | Enable or disable C++20 native `u8` literal support as `const char8_t` (off by default, except under **`/std:c++20`**). |
| [`/Zc:enumTypes[-]`](zc-enumtypes.md) | Enable Standard C++ rules for `enum` type deduction (off by default). |
| [`/Zc:externC[-]`](zc-externc.md) | Enforce Standard C++ rules for `extern "C"` functions (implied by **`/permissive-`**). |
| [`/Zc:externConstexpr[-]`](zc-externconstexpr.md) | Enable external linkage for **`constexpr`** variables (off by default). |
| [`/Zc:forScope[-]`](zc-forscope-force-conformance-in-for-loop-scope.md) | Enforce Standard C++ **`for`** scoping rules (on by default). |
Expand Down
6 changes: 4 additions & 2 deletions docs/build/reference/compiler-options-listed-by-category.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Compiler Options Listed by Category"
description: "Reference listing by category of the Microsoft C/C++ compiler command-line options."
ms.date: 04/15/2022
ms.date: 11/07/2022
helpviewer_keywords: ["compiler options, C++"]
ms.assetid: c4750dcf-dba0-4229-99b6-45cdecc11729
---
Expand Down Expand Up @@ -173,10 +173,12 @@ This article contains a categorical list of compiler options. For an alphabetica
| [`/vmv`](vmm-vms-vmv-general-purpose-representation.md) | Declares virtual inheritance. |
| [`/Z7`](z7-zi-zi-debug-information-format.md) | Generates C 7.0-compatible debugging information. |
| [`/Za`](za-ze-disable-language-extensions.md) | Disables some C89 language extensions in C code. |
| [`/Zc:__cplusplus[-]`](zc-cplusplus.md) | Enable the `__cplusplus` macro to report the supported standard (off by default). |
| [`/Zc:__STDC__`](zc-stdc.md) | Enable the `__STDC__` macro to report the C standard is supported (off by default). |
| [`/Zc:alignedNew[-]`](zc-alignednew.md) | Enable C++17 over-aligned dynamic allocation (on by default in C++17). |
| [`/Zc:auto[-]`](zc-auto-deduce-variable-type.md) | Enforce the new Standard C++ meaning for **`auto`** (on by default). |
| [`/Zc:char8_t[-]`](zc-char8-t.md) | Enable or disable C++20 native `u8` literal support as `const char8_t` (off by default, except under **`/std:c++20`**). |
| [`/Zc:__cplusplus[-]`](zc-cplusplus.md) | Enable the `__cplusplus` macro to report the supported standard (off by default). |
| [`/Zc:enumTypes[-]`](zc-enumtypes.md) | Enable Standard C++ rules for inferred `enum` base types (Off b y default, not implied by **`/permissive-`**). |
| [`/Zc:externC[-]`](zc-externc.md) | Enforce Standard C++ rules for `extern "C"` functions (implied by **`/permissive-`**). |
| [`/Zc:externConstexpr[-]`](zc-externconstexpr.md) | Enable external linkage for **`constexpr`** variables (off by default). |
| [`/Zc:forScope[-]`](zc-forscope-force-conformance-in-for-loop-scope.md) | Enforce Standard C++ **`for`** scoping rules (on by default). |
Expand Down
88 changes: 88 additions & 0 deletions docs/build/reference/zc-enumtypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
description: "Learn more about the /Zc:enumTypes (Enable enum type deduction) compiler option."
title: "/Zc:enumTypes (Enable enum type deduction)"
ms.date: 11/07/2022
f1_keywords: ["/Zc:enumTypes"]
helpviewer_keywords: ["-Zc:enumTypes compiler option (C++)", "/Zc:enumTypes compiler option (C++)"]
---
# `/Zc:enumTypes` (Enable enum type deduction)

The **`/Zc:enumTypes`** compiler option enables C++ conforming **`enum`** underlying type and enumerator type deduction.

## Syntax

> **`/Zc:enumTypes`**\[**`-`**]

## Remarks

The **`/Zc:enumTypes`** compiler option implements Standard C++ conforming behavior for deduction of enumeration base types and the types of enumerators.

The **`/Zc:enumTypes`** option is new in Visual Studio 2022 version 17.4. This option is off by default, and isn't enabled by **`/permissive-`**. To explicitly disable the option, use **`/Zc:enumTypes-`**.

When enabled, the **`/Zc:enumTypes`** option is a potential source and binary breaking change. Some enumeration types change size when the conforming **`/Zc:enumTypes`** option is enabled. Certain Windows SDK headers include such enumeration definitions.

The C++ Standard requires that the underlying type of an enumeration is large enough to hold all enumerators declared in it. Sufficiently large enumerators can set the underlying type of the **`enum`** to **`unsigned int`**, **`long long`**, or **`unsigned long long`**. Previously, such enumeration types always had an underlying type of **`int`** in the Microsoft compiler, regardless of enumerator values.

The C++ Standard also specifies that, within an enumeration definition that has no fixed underlying type, the types of enumerators are determined by their initializers. Or, for the enumerators with no initializer, by the type of the previous enumerator (accounting for overflow). Previously, such enumerators were always given the deduced type of the enumeration, with a placeholder for the underlying type (typically **`int`**).

In versions of Visual Studio before Visual Studio 2022 version 17.4, the C++ compiler didn't correctly determine the underlying type of an unscoped enumeration with no fixed base type. The compiler also didn't correctly model the types of enumerators. It could assume an incorrect type in enumerations without a fixed underlying type before the closing brace of the enumeration. Under **`/Zc:enumTypes`**, the compiler correctly implements the standard behavior.

### Example: Underlying type of unscoped `enum` with no fixed type

```cpp
enum Unsigned
{
A = 0xFFFFFFFF // Value 'A' does not fit in 'int'.
};

// Previously, this static_assert failed. It passes with /Zc:enumTypes.
static_assert(std::is_same_v<std::underlying_type_t<Unsigned>, unsigned int>);

template <typename T>
void f(T x)
{
}

int main()
{
// Previously called f<int>, now calls f<unsigned int>.
f(+A);
}

// Previously, this enum would have an underlying type of `int`,
// but Standard C++ requires this to have a 64-bit underlying type.
// The /Zc:enumTypes option changes the size of this enum from 4 to 8,
// which could impact binary compatibility with code compiled with an
// earlier compiler version, or without the switch.
enum Changed
{
X = -1,
Y = 0xFFFFFFFF
};
```

### Example: Enumerators within an `enum` definition with no fixed underlying type

```cpp
enum Enum {
A = 'A',
B = sizeof(A)
};

static_assert(B == 1); // previously failed, now succeeds under /Zc:enumTypes
```

In this example the enumerator `A` should have type **`char`** prior to the closing brace of the enumeration, so `B` should be initialized using `sizeof(char)`. Before the **`/Zc:enumTypes`** fix, `A` had enumeration type `Enum` with a deduced underlying type **`int`**, and `B` was initialized using `sizeof(Enum)`, or 4.

### To set this compiler option in Visual Studio

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

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

1. In **Additional options**, add *`/Zc:enumTypes`* or *`/Zc:enumTypes-`*. Choose **OK** or **Apply** to save your changes.

## See also

[`/Zc` (Conformance)](zc-conformance.md)\
[`/std` (Specify language standard version)](std-specify-language-standard-version.md)
60 changes: 60 additions & 0 deletions docs/build/reference/zc-stdc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
description: "Learn more about the /Zc:__STDC__ (Enable __STDC__ macro) compiler option."
title: "/Zc:__STDC__ (Enable __STDC__ macro)"
ms.date: 11/07/2022
f1_keywords: ["/Zc:__STDC__"]
helpviewer_keywords: ["-Zc:__STDC__ compiler option (C++)", "/Zc:__STDC__ compiler option (C++)"]
---
# `/Zc:__STDC__` (Enable `__STDC__` macro)

The **`/Zc:__STDC__`** compiler option defines the built-in `__STDC__` preprocessor macro as 1 in C code.

## Syntax

> **`/Zc:__STDC__`**

## Remarks

The **`/Zc:__STDC__`** compiler option implements Standard C conforming behavior for the `__STDC__` preprocessor macro, setting it to 1 when compiling C11 and C17 code.

The **`/Zc:__STDC__`** option is new in Visual Studio 2022 version 17.2. This option is off by default, but can be enabled explicitly when **`/std:c11`** or **`/std:c17`** is specified. There's no negative version of the option.

This option is a source breaking change. Due to the behavior of the UCRT, which doesn't expose POSIX functions when `__STDC__` is `1`, it isn't possible to define this macro for C by default without introducing breaking changes to the stable language versions.

### Example

```c
// test__STDC__.c
#include <io.h>
#include <fcntl.h>
#include <stdio.h>

int main() {
#if __STDC__
int f = _open("file.txt", _O_RDONLY);
_close(f);
#else
int f = open("file.txt", O_RDONLY);
close(f);
#endif
}

/* Command line behavior

C:\Temp>cl /EHsc /W4 /Zc:__STDC__ test__STDC__.c && test__STDC__

*/
```

### To set this compiler option in Visual Studio

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

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

1. In **Additional options**, add *`/Zc:__STDC__`*. Choose **OK** or **Apply** to save your changes.

## See also

[`/Zc` (Conformance)](zc-conformance.md)\
[`/std` (Specify language standard version)](std-specify-language-standard-version.md)
8 changes: 6 additions & 2 deletions docs/build/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,18 @@ items:
items:
- name: /Zc (Conformance)
href: ../build/reference/zc-conformance.md
- name: "/Zc:__cplusplus (Enable updated __cplusplus macro)"
href: ../build/reference/zc-cplusplus.md
- name: "/Zc:__STDC__ (Enable __STDC__ macro)"
href: ../build/reference/zc-stdc.md
- name: "/Zc:alignedNew (C++17 over-aligned allocation)"
href: ../build/reference/zc-alignednew.md
- name: "/Zc:auto (Deduce variable type)"
href: ../build/reference/zc-auto-deduce-variable-type.md
- name: "/Zc:char8_t (Enable C++20 char8_t type)"
href: ../build/reference/zc-char8-t.md
- name: "/Zc:__cplusplus (Enable updated __cplusplus macro)"
href: ../build/reference/zc-cplusplus.md
- name: '/Zc:enumTypes (Enable enum type deduction)'
href: ../build/reference/zc-enumtypes.md
- name: '/Zc:externC (Use Standard C++ extern "C" rules)'
href: ../build/reference/zc-externc.md
- name: "/Zc:externConstexpr (Enable extern constexpr variables)"
Expand Down
2 changes: 1 addition & 1 deletion docs/c-runtime-library/locale.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Learn more about: Locale"
title: "Locale"
ms.date: "04/11/2018"
f1_keywords: ["c.international"]
helpviewer_keywords: ["localization, locale", "country information", "language information routines", "setlocale function", "locale routines"]
helpviewer_keywords: ["localization, locale", "country/region information", "language information routines", "setlocale function", "locale routines"]
---
# Locale

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Compiler Warnings by compiler version"
description: "Table of Microsoft C/C++ compiler warnings by compiler version."
ms.date: 08/08/2022
ms.date: 11/07/2022
helpviewer_keywords: ["warnings, by compiler version", "cl.exe compiler, setting warning options"]
---
# Compiler Warnings by compiler version
Expand Down Expand Up @@ -46,13 +46,26 @@ These versions of the compiler introduced new warnings:
| Visual Studio 2022 version 17.1 | 19.31 |
| Visual Studio 2022 version 17.2 | 19.32 |
| Visual Studio 2022 version 17.3 | 19.33 |
| Visual Studio 2022 version 17.4 | 19.34 |

You can specify only the major number, the major and minor numbers, or the major, minor, and build numbers to the **`/Wv`** option. The compiler reports all warnings that match versions that begin with the specified number. It suppresses all warnings for versions greater than the specified number. For example, **`/Wv:17`** reports warnings introduced in or before any version of Visual Studio 2012, and suppresses warnings introduced by any compiler from Visual Studio 2013 (version 18) or later. To suppress warnings introduced in Visual Studio 2015 update 2 and later, you can use **`/Wv:19.00.23506`**. Use **`/Wv:19.11`** to report the warnings introduced in any version of Visual Studio before Visual Studio 2017 version 15.5, but suppress warnings introduced in Visual Studio 2017 version 15.5 and later.

The following sections list the warnings introduced by each version of Visual C++ that you can suppress by using the **`/Wv`** compiler option. The **`/Wv`** option can't suppress warnings that aren't listed, which predate the specified versions of the compiler.

::: moniker range=">= msvc-170"

## Warnings introduced in Visual Studio 2022 version 17.4 (compiler version 19.34)

These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.33`**.

| Warning | Message |
|--|--|
| C5260 | the constant variable '*variable-name*' has internal linkage in an included header file context, but external linkage in imported header unit context; consider declaring it '`inline`' as well if it will be shared across translation units, or '`static`' to express intent to use it local to this translation unit |
| C5261 | no integer type can represent all enumerator values in enumeration '*enum-name*' |
| C5262 | implicit fall-through occurs here; are you missing a `break` statement? Use `[[fallthrough]]` when a `break` statement is intentionally omitted between cases |
| C5263 | calling '`std::move`' on a temporary object prevents copy elision |
| C5264 | '*variable-name*': '`const`' variable is not used |

## Warnings introduced in Visual Studio 2022 version 17.3 (compiler version 19.33)

These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.32`**.
Expand Down
Loading