Skip to content

Commit eeb8279

Browse files
authored
Merge pull request MicrosoftDocs#3663 from MicrosoftDocs/main637783870996186695
Repo sync for protected CLA branch
2 parents cef6354 + 47a6524 commit eeb8279

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

docs/build/reference/zc-conformance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Here are the **`/Zc`** compiler options:
3939
| [`/Zc:rvalueCast`](zc-rvaluecast-enforce-type-conversion-rules.md) | Enforce Standard C++ explicit type conversion rules (off by default). |
4040
| [`/Zc:sizedDealloc`](zc-sizeddealloc-enable-global-sized-dealloc-functions.md) | Enable C++14 global sized deallocation functions (on by default). |
4141
| [`/Zc:strictStrings`](zc-strictstrings-disable-string-literal-type-conversion.md) | Disable string-literal to `char*` or `wchar_t*` conversion (off by default). |
42+
| [`/Zc:static_assert`](zc-static-assert.md) | strict handling of `static_assert` (implied by **`/permissive-`**). |
4243
| [`/Zc:ternary`](zc-ternary.md) | Enforce conditional operator rules on operand types (off by default). |
4344
| [`/Zc:threadSafeInit`](zc-threadsafeinit-thread-safe-local-static-initialization.md) | Enable thread-safe local static initialization (on by default). |
4445
| [`/Zc:throwingNew`](zc-throwingnew-assume-operator-new-throws.md) | Assume **`operator new`** throws on failure (off by default). |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
description: "Learn more about: /Zc:static_assert (Strict static_assert handling)"
3+
title: "/Zc:static_assert (Strict static_assert handling)"
4+
ms.date: 12/15/2021
5+
f1_keywords: ["/Zc:static_assert"]
6+
helpviewer_keywords: ["/Zc:static_assert compiler option (C++)"]
7+
---
8+
# `/Zc:static_assert` (Strict static_assert handling)
9+
10+
The **`/Zc:static_assert`** compiler option tells the compiler to evaluate `static_assert` calls with non-dependent test expressions when class or function templates are parsed.
11+
12+
## Syntax
13+
14+
> **`/Zc:static_assert`**\
15+
> **`/Zc:static_assert-`**
16+
17+
## Remarks
18+
19+
The **`/Zc:static_assert`** compiler option tells the compiler to evaluate a `static_assert` in the body of a function template or in the body of a class template member function when first parsed, if the test expression isn't dependent. If the non-dependent test expression isn't `false`, the compiler emits an error immediately. When the test expression is dependent, the `static_assert` isn't evaluated until the template is instantiated.
20+
21+
The **`/Zc:static_assert`** option is available starting in Visual Studio 2022 version 17.1. In earlier versions of Visual Studio, or if **`/Zc:static_assert-`** is specified, Visual Studio doesn't do dependent analysis if the `static_assert` is within the body of a function template or within the body of a member function of a class template. Instead, it only evaluates the `static_assert` when a template is instantiated.
22+
23+
The **`/permissive-`** option enables **`/Zc:static_assert`**, so it's on by default in projects that use **`/std:c++20`** or **`/std:c++latest`**. The **`/Zc:static_assert-`** option must come after a **`/std:c++20`**, **`/std:c++latest`**, or **`/permissive-`** option on the command line.
24+
25+
If the compiler is in the default C++14 mode and **`/permissive-`** or **`/Zc:static_assert`** is specified, it uses **`/Zc:static_assert`** behavior. However, if it evaluates a `static_assert` in a template body, it also reports off-by-default warning C5254, "language feature 'terse static assert' requires compiler flag '**`/std:c++17`**'", since this behavior isn't required until C++17.
26+
27+
### To set this compiler option in Visual Studio
28+
29+
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).
30+
31+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
32+
33+
1. Add **`/Zc:static_assert`** or **`/Zc:static_assert-`** to the **Additional options:** pane.
34+
35+
## See also
36+
37+
[`/Zc` (Conformance)](zc-conformance.md)

docs/build/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ items:
798798
href: ../build/reference/zc-rvaluecast-enforce-type-conversion-rules.md
799799
- name: "/Zc:sizedDealloc (Enable global sized deallocation functions)"
800800
href: ../build/reference/zc-sizeddealloc-enable-global-sized-dealloc-functions.md
801+
- name: "/Zc:static_assert (Strict static_assert handling)"
802+
href: ../build/reference/zc-static-assert.md
801803
- name: "/Zc:strictStrings (Disable string literal type conversion)"
802804
href: ../build/reference/zc-strictstrings-disable-string-literal-type-conversion.md
803805
- name: "/Zc:ternary (Enforce conditional operator rules)"

0 commit comments

Comments
 (0)