[Bug c++/56742] New: Optimization bug lead to uncaught throw

ktietz at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 26 15:56:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56742

             Bug #: 56742
           Summary: Optimization bug lead to uncaught throw
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ktietz@gcc.gnu.org
            Target: x86_64-w64-mingw32, x86_64-pc-cygwin


Hi,

the following testcase:

#include <string>

static int main_worker(int argc)
{
  std::string s[32]; // [31] => no segfault
  if (argc < 2)
    throw 42;
  return argc;
}

int main(int argc, char **argv)
{
  try {
    return main_worker(argc);
  }
  catch (int i) {
    return i;
  }
}

produces with optimization -O2 on execution the message:
 "terminate called after throwing an instance of 'int'"
and abort gets called.

If compiled with optimization level -O1, execution works as expected.



More information about the Gcc-bugs mailing list