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

            Bug ID: 78651
           Summary: Incorrect exception handling when catch clause uses
                    local class and PIC and sanitizer are active
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dyp-cpp at gmx dot net
  Target Milestone: ---

Consider the following program:


#include <iostream>

#ifndef EXCEPTION_TYPE
#  define EXCEPTION_TYPE LocalException
#endif

#define STRINGIFY(X) STRINGIFY2(X)
#define STRINGIFY2(X) #X

struct Exception {};

int main()
{
  struct LocalException {};

  try
  {
    std::cout << "throwing int\n";
    throw 42;
  }catch(EXCEPTION_TYPE const& d)
  {
    std::cout << "caught " STRINGIFY(EXCEPTION_TYPE) "\n";
  }catch(...)
  {
    std::cout << "caught ...\n";
  }
}


Compile with -fPIC -fsanitize=address on x86-64, then the first catch clause
(EXCEPTION_TYPE const&) is executed. If you drop either option (fPIC or
fsanitize), then the second catch clause is executed. I ran into this issue on
g++4.8.5, but the behaviour is still the same with the current master branch.

By setting -DEXCEPTION_TYPE=Exception, the first catch clause uses a non-local
class and is never executed, even with -fPIC and -fsanitize.

Problem does not occur on clang++.

Reply via email to