https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71909
Bug ID: 71909
Summary: g++ accepts an unreachable function catch block that
lacks a corresponding try
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: db0451 at gmail dot com
Target Milestone: ---
via http://stackoverflow.com/questions/38415131
The Standard requires a function-try block to have a corresponding
post-function catch block and vice-versa. But g++ will merrily compile the
following without saying anything, even with -std=c++14 -Wall -Wextra
-Wpedantic
struct foo
{
void bar()
{
}
catch (...)
{
}
};
int main ()
{
foo f;
f.bar();
return 0;
}
I presume the parser never checks for this case - somewhat understandable as
function-try is rare enough even when it _is_ used properly - but g++ should
generate an error on this code because it is not well-formed.