In libc++ is std::make_shared supposed to have a dependency on RTTI?

During migrating some code from various hand rolled smart pointers to
C++11 stuff I noticed a crash, and I am not sure if it is due to a bug
in libc++ or me not understanding some of the dependencies in the new
C++ standard. I was seeing crashes in ~shared_ptr, it appears to be
walking into garbage, presumably looking for type info (the code has
always been compiled -fno-rtti). If I turn on RTTI it goes away, and
if I manually construct the shared_ptr instead of using make_shared it
also goes away.

Below is a reduced test case that shows what is going on. If this
dependency should not exist I am happy to file a bug, but I wanted to
confirm that it is in fact a bug.

Louis

/* testcase.cpp
   /Developer/usr/bin/clang++ --std=c++0x --stdlib=libc++ -fno-rtti
testcase.cpp
*/

//Crashes on scope collapse when ~shared_ptr is called.
// Crash goes away if RTTI is turned on
// Crash also goes away if the "SharedTest test = SharedTest(NULL);"
instead of std::make_shared

#include <memory>

typedef std::shared_ptr<void *> SharedTest;

int main (void) {
  SharedTest test = std::make_shared<void *>(NULL);
  return 0;
}

I can’t seem to repro this with ToT clang/llvm/libc++ on linux x86-64. Could you provide more details about your repro?

(& the resulting binary is valgrind clean too, which should reduce the chance that I’m just seeing a different case of undefined behaviour than you)

  • David

Hello,

During migrating some code from various hand rolled smart pointers to
C++11 stuff I noticed a crash, and I am not sure if it is due to a bug
in libc++ or me not understanding some of the dependencies in the new
C++ standard. I was seeing crashes in ~shared_ptr, it appears to be
walking into garbage, presumably looking for type info (the code has
always been compiled -fno-rtti). If I turn on RTTI it goes away, and
if I manually construct the shared_ptr instead of using make_shared it
also goes away.

I think this was fixed in a recent change to libc++. What revision of it do
you use?

If it's not possible for you to upgrade to a newer libc++ revision, you should
be able to solve the problem by recompiling libc++ without RTTI (meaning you
would have two versions of it: libc++.rtti and libc++.north).

Jonathan