/Zc:noexceptTypes (C++17 noexcept rules)

The C++17 standard makes throw() as an alias for noexcept, removes throw(<type list>) and throw(...), and allows certain types to include noexcept. This can cause a number of source compatibility issues in code that conforms to C++14 or earlier. The /Zc:noexceptTypes option can specify conformance to the C++17 standard or allow the C++14 and earlier behavior when code is compiled in C++17 mode.

Syntax

/Zc:noexceptTypes[-]

Remarks

When the /Zc:noexceptTypes option is specified, the compiler conforms to the C++17 standard and treats throw() as an alias for noexcept, removes throw(<type list>) and throw(...), and allows certain types to include noexcept. The /Zc:noexceptTypes option is only available when /std:c++17 or /std:latest is enabled. /Zc:noexceptTypes is enabled by default to conform to the ISO C++17 standard. The /permissive- option does not affect /Zc:noexceptTypes. Turn this option off by specifying /Zc:noexceptTypes- to revert to the C++14 behavior of noexcept when /std::C++17 or /std::latest is specified.

Beginning in Visual Studio 2017 version 15.5, the C++ compiler diagnoses more mismatched exception specifications in declarations in C++17 mode or when the /permissive- option is specified.

This sample shows how declarations with an exception specifier behave when the /Zc:noexceptTypes option is set or disabled. To show the behavior when set, compile by using cl /EHsc /W4 noexceptTypes.cpp. To show the behavior when disabled, compile by using cl /EHsc /W4 /Zc:noexceptTypes- noexceptTypes.cpp.

// noexceptTypes.cpp
// Compile by using: cl /EHsc /W4 noexceptTypes.cpp
// Compile by using: cl /EHsc /W4 /Zc:noexceptTypes- noexceptTypes.cpp

void f() throw();    // equivalent to void f() noexcept;
void f() { }         // warning C5043
void g() throw(...); // warning C5040

struct A
{
    virtual void f() throw();
};

struct B : A
{
    virtual void f() { } // error C2694
};

When compiled by using the default setting /Zc:noexceptTypes, the sample generates the listed warnings. To update your code, use the following instead:

void f() noexcept;
void f() noexcept { }
void g() noexcept(false);

struct A
{
    virtual void f() noexcept;
};

struct B : A
{
    virtual void f() noexcept { }
};

For more information about conformance issues in Visual C++, see Nonstandard Behavior.

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Working with Project Properties.

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

  3. Modify the Additional Options property to include /Zc:noexceptTypes or /Zc:noexceptTypes- and then choose OK.

See also

/Zc (Conformance) noexcept
Exception Specifications (throw)