title: Catching derived exceptions types fails on Clang/MacOS X
body: <p>I have a C++ library which I'm trying to get running on Mac OS X with Clang. The library consists of a DLL and a Unit-Test executable. It compiles fine with GCC and MSVC, with GCC, I use the following settings:</p>
  
  <ul>
  <li>The library is compiled with <code>-fvisibility=hidden</code></li>
  <li>All exposed classes are explicitly marked as <code>__attribute__(visibility("default"))</code></li>
  <li>The library has some exception classes, derived from <code>std::runtime_error</code>. All such classes are marked for default visibility. There is a root class <code>LibraryException</code> from which more specific exceptions are derived.</li>
  <li>On GCC, I use <code>-std=c++0x</code>, with clang, both the library and the unit test executable is built with <code>-stdlib=libc++ -std=c++11</code></li>
  </ul>
  
  <p>On Mac OS X, the unit test framework now fails, because exceptions are of the wrong type. I.e. a test like this fails:</p>
  
  <pre><code>// bla.foo () throws CustomException, which is derived from LibraryException
  TEST_THROWS (bla.foo (), CustomException)
  
  // This works however
  TEST_THROWS (bla.foo (), LibraryException)
  </code></pre>
  
  <p>I verified that the typeinfo and vtable of my custom exception classes is exported using <code>nm -g library.dylib | c++filt -p -i</code>. This seems to be the case for all exceptions ... what the heck is going on here? I have tried to debug on the of the errors, and I see how the correct type is being thrown in the library and yet the same type cannot be caught in the unit test executable. Is there something special required with Clang to get this working? I'm using the latest googletest framework from SVN for testing.</p>
  
  <p>A small test program exhibits the same problem:</p>
  
  <pre><code>try {
      funcThatThrowsCustomExceptionFromLibraryDylib ();
  } catch (CustomException&amp; e) {
      // doesn't get here
  } catch (LibraryException&amp; e) {
      // does get here
      // after demangle, this prints CustomException
      // Can cast down to CustomException and access the fields as well
      std::cout &lt;&lt; typeid (e).name () &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>It also fails for instance when a <code>boost::lexical_cast</code> exception is thrown from the Library.</p>