| title | /Zc:auto (Deduce Variable Type) | ||||
|---|---|---|---|---|---|
| ms.date | 02/28/2018 | ||||
| f1_keywords |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | 5f5bc102-44c3-4688-bbe1-080594dcee5c |
The /Zc:auto[-] compiler option tells the compiler how to use the auto keyword to declare variables. If you specify the default option, /Zc:auto, the compiler deduces the type of the declared variable from its initialization expression. If you specify /Zc:auto-, the compiler allocates the variable to the automatic storage class.
/Zc:auto[-]
The C++ standard defines an original and a revised meaning for the auto keyword. Before Visual Studio 2010, the keyword declares a variable in the automatic storage class; that is, a variable that has a local lifetime. Starting with Visual Studio 2010, the keyword deduces the type of a variable from the declaration's initialization expression. Use the /Zc:auto[-] compiler option to tell the compiler to use the original or revised meaning of the auto keyword. The /Zc:auto option is on by default. The /permissive- option does not change the default setting of /Zc:auto.
The compiler issues an appropriate diagnostic message if your use of the auto keyword contradicts the current /Zc:auto compiler option. For more information, see auto Keyword. For more information about conformance issues with Visual C++, see Nonstandard Behavior.
-
Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.
-
Select the Configuration Properties > C/C++ > Command Line property page.
-
Add /Zc:auto or /Zc:auto- to the Additional options: pane.