https://gcc.gnu.org/bugzilla/show_bug.cgi?id=4898

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #2)
> I agree a new warning would be useful. For example, the following code should
> be diagnosed:
> 
> struct S { S () throw () { throw 0; } };

This is still relevant in current standards, where throw() is equivalent to
noexcept.

Clang warns:

throw.cc:1:28: warning: 'S' has a non-throwing exception specification but can
still throw [-Wexceptions]
struct S { S () throw () { throw 0; } };
                           ^
throw.cc:1:12: note: function declared non-throwing here
struct S { S () throw () { throw 0; } };
           ^    ~~~~~~~~
1 warning generated.


GCC only warns if we replace throw() with noexcept:

struct S { S () noexcept { throw 0; } };

throw.cc: In constructor 'S::S()':
throw.cc:1:34: warning: throw will always call terminate() [-Wterminate]
1 | struct S { S () noexcept { throw ""; } };
  |                                  ^~

We should warn for the equivalent throw() as well.


> as should this:
> 
> struct S { S () throw (int) { throw ""; } };

Clang doesn't bother warning about this, with -std=c++98 or any other mode.

Reply via email to