[Bug c++/94112] Please add a warning for potentially throwing code in noexcept function

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 10 15:34:53 GMT 2020


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-03-10
                 CC|                            |msebor at gcc dot gnu.org
             Blocks|                            |87403

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed with the output below.  -Wterminate is fully implemented in the C++
front-end so it doesn't know about what might happen in called functions. 
Implementing the detection across inlined functions requires moving the warning
to the middle-end and deciding how to deal with situations where the called
function throws only under some non-constant conditions (e.g., issue
-Wterminate regardless, or a -Wmaybe-terminate kind of a warning, or none).

$ gcc -O2 -Wall -Wextra -S -Wall a.C
void foo () noexcept
{
    throw 42;
}

static void bar ()
{
    throw 42;
}

void foobar () noexcept
{ 
    bar ();
}

a.C: In function ‘void foo()’:
a.C:3:5: warning: ‘throw’ will always call ‘terminate’ [-Wterminate]
    3 |     throw 42;
      |     ^~~~~~~~


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning


More information about the Gcc-bugs mailing list