[LLVMbugs] [Bug 7132] New: [C++ CodeGen] Cannot catch std::bad_cast

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 13 14:44:34 PDT 2010


           Summary: [C++ CodeGen] Cannot catch std::bad_cast
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: dgregor at apple.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com
            Blocks: 6023

We aren't able to catch a std::bad_cast in a catch block, as in the following

terfin:clang dgregor$ cat t.cpp 
#include <typeinfo>

extern "C" void abort();
extern "C" int printf(const char*, ...);

struct A { virtual ~A() { } };
struct B : A { virtual ~B() { } };

int main() {
  A *a = new A();
  try {
    printf("Survived dynamic_cast?\n");
  } catch (const std::bad_cast &) {
    // Okay
    return 0;

  printf("Did not catch std::bad_cast?\n");
  return 0;
terfin:clang dgregor$ clang++ t.cpp && ./a.out
Survived dynamic_cast?
Abort trap
terfin:clang dgregor$ g++ t.cpp && ./a.out

The problem is in the "catch" handling; if g++ compiles the try/catch and
either clang or g++ compile the dynamic_cast, the program works as expected. If
clang compiles the try/catch, it fails.

This affects Boost.StateChart.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list