Skip to content

Commit 5b086e7

Browse files
author
Colin Robertson
committed
Create remaining conformance topics
1 parent 64757fd commit 5b086e7

4 files changed

+172
-19
lines changed

docs/build/reference/zc-conformance.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,35 @@ translation.priority.ht:
3838
- "zh-tw"
3939
---
4040
# /Zc (Conformance)
41-
You can use the **/Zc** compiler options to specify standard or Microsoft-specific compiler behavior. Here are the **/Zc** compiler options:
41+
You can use the **/Zc** compiler options to specify standard or Microsoft-specific compiler behavior.
42+
43+
## Syntax
44+
45+
`/Zc:`_option_{,_option_}
46+
47+
## Remarks
48+
49+
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.
50+
51+
These are the `/Zc` compiler options:
4252

4353
|Option|Behavior|
4454
|---|---|
45-
|[auto\[-\]](../../build/reference/zc-auto-deduce-variable-type.md)|Enforce the new Standard C++ meaning for `auto`.|
46-
|[forScope\[-\]](../../build/reference/zc-forscope-force-conformance-in-for-loop-scope.md)|Enforce Standard C++ `for` scoping rules.|
47-
|[implicitNoexcept\[-\]](../../build/reference/zc-implicitnoexcept-implicit-exception-specifiers.md)|Enable implicit noexcept on required functions.|
48-
|[inline\[-\]](../../build/reference/zc-inline-remove-unreferenced-comdat.md)|Remove unreferenced function or data if it is COMDAT or has internal linkage only (off by default).|
55+
|[auto\[-\]](zc-auto-deduce-variable-type.md)|Enforce the new Standard C++ meaning for `auto` (on by default).|
56+
|[forScope\[-\]](zc-forscope-force-conformance-in-for-loop-scope.md)|Enforce Standard C++ `for` scoping rules (on by default).|
57+
|[implicitNoexcept\[-\]](zc-implicitnoexcept-implicit-exception-specifiers.md)|Enable implicit `noexcept` on required functions (on by default).|
58+
|[inline\[-\]](zc-inline-remove-unreferenced-comdat.md)|Remove unreferenced function or data if it is COMDAT or has internal linkage only (off by default).|
4959
|[referenceBinding\[-\]](zc-referencebinding-enforce-reference-binding-rules.md)|A UDT temporary will not bind to an non-const lvalue reference (off by default).|
50-
|[rvalueCast\[-\]](../../build/reference/zc-rvaluecast-enforce-type-conversion-rules.md)|Enforce Standard C++ explicit type conversion rules.|
51-
|[sizedDealloc\[-\]]()|Enable C++14 global sized deallocation functions (on by default).|
52-
|[strictStrings\[-\]](../../build/reference/zc-strictstrings-disable-string-literal-type-conversion.md)|Disable string-literal to `char*` or `wchar_t*` conversion (off by default).|
53-
|[threadSafeInit\[-\]]()|Enable thread-safe local static initialization.|
54-
|[throwingNew\[-\]]()|Assume `operator new` throws on failure (off by default).|
55-
|[trigraphs\[-\]](../../build/reference/zc-trigraphs-trigraphs-substitution.md)|Enable trigraphs (obsolete, off by default).|
56-
|[wchar_t\[-\]](../../build/reference/zc-wchar-t-wchar-t-is-native-type.md)|`wchar_t` is a native type, not a typedef.|
60+
|[rvalueCast\[-\]](zc-rvaluecast-enforce-type-conversion-rules.md)|Enforce Standard C++ explicit type conversion rules (on by default).|
61+
|[sizedDealloc\[-\]](zc-sizeddealloc-enable-global-sized-dealloc-functions.md)|Enable C++14 global sized deallocation functions (on by default).|
62+
|[strictStrings\[-\]](zc-strictstrings-disable-string-literal-type-conversion.md)|Disable string-literal to `char*` or `wchar_t*` conversion (off by default).|
63+
|[threadSafeInit\[-\]](zc-threadsafeinit-thread-safe-local-static-initialization.md)|Enable thread-safe local static initialization (on by default).|
64+
|[throwingNew\[-\]](zc-throwingnew-assume-operator-new-throws.md)|Assume `operator new` throws on failure (off by default).|
65+
|[trigraphs\[-\]](zc-trigraphs-trigraphs-substitution.md)|Enable trigraphs (obsolete, off by default).|
66+
|[wchar_t\[-\]](zc-wchar-t-wchar-t-is-native-type.md)|`wchar_t` is a native type, not a typedef (on by default).|
5767

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

6070
## See Also
61-
[Compiler Options](../../build/reference/compiler-options.md)
62-
[Setting Compiler Options](../../build/reference/setting-compiler-options.md)
71+
[Compiler Options](compiler-options.md)
72+
[Setting Compiler Options](setting-compiler-options.md)

docs/build/reference/zc-sizeddealloc-enable-global-sized-dealloc-functions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ In the C++11 standard, you may define static member functions `operator delete`
5151

5252
The C++14 standard changes the behavior of the compiler. When you define global `operator delete` and `operator delete[]` that take a second parameter of type `size_t`, the compiler prefers to call these functions when member scope versions are not invoked and the size of the object is available. The compiler passes the size argument implicitly. The single argument versions are called when the compiler can't determine the size of the object being deallocated. Otherwise, the usual rules for choosing the version of the deallocation function to invoke still apply. Calls to the global functions may be explicitly specified by prepending the scope resolution operator (`::`) to the deallocation function call.
5353

54-
By default, Visual C++ starting in Visual Studio 2015 implements this C++14 standard behavior. You may explicitly specify this by setting the **/Zc:sizedDealloc** compiler option. This represents a potentially breaking change. Use the **/Zc:sizedDealloc-** option to preserve the old behavior, for example, when your code defines placement delete operators that use a second parameter of type `size_t`. The default Visual Studio library implementations of the global deallocation functions that have the second parameter of type `size_t` invoke the single parameter versions.
54+
By default, Visual C++ starting in Visual Studio 2015 implements this C++14 standard behavior. You may explicitly specify this by setting the `/Zc:sizedDealloc` compiler option. This represents a potentially breaking change. Use the `/Zc:sizedDealloc-` option to preserve the old behavior, for example, when your code defines placement delete operators that use a second parameter of type `size_t`. The default Visual Studio library implementations of the global deallocation functions that have the second parameter of type `size_t` invoke the single parameter versions. If your code supplies only single-parameter global operator delete and operator delete[], the default library implementations of the global sized deallocation functions invoke your global functions.
5555

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

5858
## To set this compiler option in the Visual Studio development environment
5959
1. Open the project's **Property Pages** dialog box. For details, see [Working with Project Properties](../../ide/working-with-project-properties.md).
6060
2. From the **Configurations** drop down menu, choose **All Configurations**.
6161
3. Select the **Configuration Properties**, **C/C++**, **Command Line** property page.
62-
4. Modify the **Additional Options** property to include /Zc:sizedDealloc or /Zc:sizedDealloc- and then choose **OK**.
62+
4. Modify the **Additional Options** property to include `/Zc:sizedDealloc` or `/Zc:sizedDealloc-` and then choose **OK**.
6363

6464
## See Also
65-
[Compiler Options](../../build/reference/compiler-options.md)
66-
[Setting Compiler Options](../../build/reference/setting-compiler-options.md)
67-
[/Zc (Conformance)](../../build/reference/zc-conformance.md)
65+
[Compiler Options](../../build/reference/compiler-options.md)
66+
[Setting Compiler Options](../../build/reference/setting-compiler-options.md)
67+
[/Zc (Conformance)](../../build/reference/zc-conformance.md)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "/Zc:threadSafeInit (Thread-safe Local Static Initialization) | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "12/13/2016"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "devlang-cpp"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "threadSafeInit"
13+
- "/Zc:threadSafeInit"
14+
dev_langs:
15+
- "C++"
16+
helpviewer_keywords:
17+
- "-Zc compiler options (C++)"
18+
- "threadSafeInit"
19+
- "Thread-safe Local Static Initialization"
20+
- "/Zc compiler options (C++)"
21+
- "Zc compiler options (C++)"
22+
ms.assetid: a0fc4b34-2cf0-45a7-a642-b8afc4ca19f2
23+
caps.latest.revision: 1
24+
author: "corob-msft"
25+
ms.author: "corob"
26+
manager: "ghogen"
27+
translation.priority.ht:
28+
- "cs-cz"
29+
- "de-de"
30+
- "es-es"
31+
- "fr-fr"
32+
- "it-it"
33+
- "ja-jp"
34+
- "ko-kr"
35+
- "pl-pl"
36+
- "pt-br"
37+
- "ru-ru"
38+
- "tr-tr"
39+
- "zh-cn"
40+
- "zh-tw"
41+
---
42+
# /Zc:threadSafeInit (Thread-safe Local Static Initialization)
43+
The `/Zc:threadSafeInit` compiler option tells the compiler to initialize static local (function scope) variables in a thread-safe way, eliminating the need for manual synchronization. Only initialization is thread-safe. Use and modification of static local variables by multiple threads must still be manually synchronized. This option is available starting in Visual Studio 2015. By default, Visual Studio enables this option.
44+
45+
## Syntax
46+
47+
`/Zc:threadSafeInit`[`-`]
48+
49+
## Remarks
50+
51+
In the C++11 standard, block scope variables with static or thread storage duration must be zero-initialized before any other initialization takes place. Initialization occurs when control first passes through the declaration of the variable. If an exception is thrown during initialization, the variable is considered uninitialized, and initialization is re-attempted the next time control passes through the declaration. If control enters the declaration concurrently with initialization, the concurrent execution blocks while initialization is completed. The behavior is undefined if control re-enters the declaration recursively during initialization. By default, Visual Studio starting in Visual Studio 2015 implements this standard behavior. This behavior may be explicitly specified by setting the `/Zc:threadSafeInit` compiler option.
52+
53+
Thread-safe initialization of static local variables relies on code implemented in the Universal C run-time library (UCRT). To avoid taking a dependency on the UCRT, or to preserve the non-thread-safe initialization behavior of versions of Visual Studio prior to Visual Studio 2015, use the `/Zc:threadSafeInit-` option. If you know that thread-safety is not required, use this option to generate slightly smaller, faster code around static local declarations.
54+
55+
Thread-safe static local variables use thread-local storage internally to provide efficient execution when the static has already been initialized. The implementation of this feature relies on Windows operating system support functions in Windows Vista and later operating systems. Windows XP, Windows Server 2003, and older operating systems do not have this support. To work around this issue in code that must run on older operating systems, use `/Zc:threadSafeInit-` to disable the thread-safe initialization code.
56+
57+
For more information about conformance issues in Visual C++, see [Nonstandard Behavior](../../cpp/nonstandard-behavior.md).
58+
59+
### To set this compiler option in the Visual Studio development environment
60+
1. Open the project's **Property Pages** dialog box. For details, see [Working with Project Properties](../../ide/working-with-project-properties.md).
61+
2. From the **Configurations** drop down menu, choose **All Configurations**.
62+
3. Select the **Configuration Properties**, **C/C++**, **Command Line** property page.
63+
4. Modify the **Additional Options** property to include `/Zc:threadSafeInit` or `/Zc:threadSafeInit-` and then choose **OK**.
64+
65+
## See Also
66+
[Compiler Options](../../build/reference/compiler-options.md)
67+
[Setting Compiler Options](../../build/reference/setting-compiler-options.md)
68+
[/Zc (Conformance)](../../build/reference/zc-conformance.md)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
title: "/Zc:throwingNew (Assume operator new throws) | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "12/13/2016"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "devlang-cpp"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "throwingNew"
13+
- "/Zc:throwingNew"
14+
dev_langs:
15+
- "C++"
16+
helpviewer_keywords:
17+
- "-Zc compiler options (C++)"
18+
- "throwingNew"
19+
- "Assume operator new Throws"
20+
- "/Zc compiler options (C++)"
21+
- "Zc compiler options (C++)"
22+
ms.assetid: 20ff0101-9677-4d83-8c7b-8ec9ca49f04f
23+
caps.latest.revision: 1
24+
author: "corob-msft"
25+
ms.author: "corob"
26+
manager: "ghogen"
27+
translation.priority.ht:
28+
- "cs-cz"
29+
- "de-de"
30+
- "es-es"
31+
- "fr-fr"
32+
- "it-it"
33+
- "ja-jp"
34+
- "ko-kr"
35+
- "pl-pl"
36+
- "pt-br"
37+
- "ru-ru"
38+
- "tr-tr"
39+
- "zh-cn"
40+
- "zh-tw"
41+
---
42+
# /Zc:throwingNew (Assume operator new throws)
43+
When the `/Zc:throwingNew` option is specified, the compiler optimizes calls to `operator new` to skip checks for a null pointer return. This option tells the compiler to assume that all linked implementations of `operator new` and custom allocators conform to the C++ standard and throw on allocation failure. By default in Visual Studio, the compiler pessimistically generates null checks (`/Zc:throwingNew-`) for these calls, because users can link with a non-throwing implementation of `operator new` or write custom allocator routines that return null pointers.
44+
45+
## Syntax
46+
47+
`/Zc:throwingNew`[`-`]
48+
49+
## Remarks
50+
51+
Since ISO C++98, the standard has specified that the default [operator new](../../standard-library/new-operators.md#operator_new) throws `std::bad_alloc` when memory allocation fails. Versions of Visual C++ up to Visual Studio 6.0 returned a null pointer on an allocation failure. Beginning in Visual Studio 2002, `operator new` conforms to the standard and throws on failure. To support code that uses the older allocation style, Visual Studio provides a linkable implementation of `operator new` in *nothrownew.obj* that returns a null pointer on failure. By default, the compiler also generates defensive null checks to prevent these older-style allocators from causing an immediate crash on failure. The `/Zc:throwingNew` option tells the compiler to leave out these null checks, on the assumption that all linked memory allocators conform to the standard. This does not apply to explicit non-throwing `operator new` overloads, which are declared by using an additional parameter of type `std::nothrow_t` and have an explicit `noexcept` specification.
52+
53+
Conceptually, to create an object on the free store, the compiler generates code to allocate its memory and then to invoke its constructor to initialize the memory. Because the Visual C++ compiler normally cannot tell if this code will be linked to a non-conforming, non-throwing allocator, by default it also generates a null check before calling the constructor. This prevents a null pointer dereference in the constructor call if a non-throwing allocation fails. In most cases, these checks are unnecessary, because the default `operator new` allocators throw instead of returning null pointers. The checks also have unfortunate side effects. They bloat the code size, they flood the branch predictor, and they inhibit other useful compiler optimizations such as devirtualization or const propagation out of the initialized object. The checks exist only to support code that links to *nothrownew.obj* or has custom non-conforming `operator new` implementations. If you do not use non-conforming `operator new`, we recommend you use `/Zc:throwingNew` to optimize your code.
54+
55+
If you compile by using link-time code generation (LTCG), you do not need to specify `/Zc:throwingNew`. When your code is compiled by using LTCG, the compiler can detect if the default, conforming `operator new` implementation is used. If so, the compiler leaves out the null checks automatically. The linker looks for the `/ThrowingNew` flag to tell if the implementation of `operator new` is conforming. You can specify this flag to the linker by including this directive in the source for your custom operator new implementation:
56+
57+
```cpp
58+
#pragma comment(linker, "/ThrowingNew")
59+
```
60+
61+
For more information about conformance issues in Visual C++, see [Nonstandard Behavior](../../cpp/nonstandard-behavior.md).
62+
63+
## To set this compiler option in the Visual Studio development environment
64+
1. Open the project's **Property Pages** dialog box. For details, see [Working with Project Properties](../../ide/working-with-project-properties.md).
65+
2. From the **Configurations** drop down menu, choose **All Configurations**.
66+
3. Select the **Configuration Properties**, **C/C++**, **Command Line** property page.
67+
4. Modify the **Additional Options** property to include `/Zc:throwingNew` or `/Zc:throwingNew-` and then choose **OK**.
68+
69+
## See Also
70+
[Compiler Options](../../build/reference/compiler-options.md)
71+
[Setting Compiler Options](../../build/reference/setting-compiler-options.md)
72+
[/Zc (Conformance)](../../build/reference/zc-conformance.md)
73+
[noexcept (C++)](../../cpp/noexcept-cpp.md)
74+
[Exception Specifications (throw) (C++)](../../cpp/exception-specifications-throw-cpp.md)
75+
[terminate (exception)](../../standard-library/exception-functions.md#terminate)

0 commit comments

Comments
 (0)