Search code examples
c++c++17language-lawyerexception-specification

Are compilers allowed to support a feature, that is removed in the standard?


In the first paragraph cppreference.com clearly states that throw(T1, ..., Tn) is removed in C++17.

It confuses me, that some compilers support throw(T1, ..., Tn) in C++17 mode (see demo).

  • MSVC supports it by default, but you can turn on a warning for it, see C5040. It can be turned into an error with /we5040.
  • Clang reports it as an error by default, but the error can be turned off with -Wno-dynamic-exception-spec.
  • GCC leaves you with no choice: it's an error.

Are compilers allowed to support a feature, that is removed in the standard? For what purpose?

Or is this just a compiler extension, like void foo(int size) { char a[size]; } in GCC, see demo.


Solution

  • Are compilers allowed to support a feature, that is removed in the standard?

    The standard doesn't allow that. AFAIK in general it doesn't give any special treatment to features that used to be in the language (doesn't separate them from non-existent features).

    If a compiler doesn't diagnose this error (i.e. doesn't give an error or a warning) with a specific configuration (i.e. specific flags), then it doesn't conform to the standard in that configuration.


    For what purpose?

    Backward compatibility (what else could it be). More specifically, it lets you use both old and new features in a same translation unit.

    This can be useful if you're using a library that uses a removed feature in its headers, but want to use the new language features in your own code.

    Or if you want to use the removed feature in your own code along with the new features, for some reason.


    Note that absolute conformance to the standard is not practically possible to achieve.

    Some compiler vendors care about conformance more than the others. Microsoft tends to care less about it (or at least used to, they've been working on that).