This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71909] New: g++ accepts an unreachable function catch block that lacks a corresponding try


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]