Skip to content

Instantly share code, notes, and snippets.

@dacap
Last active June 4, 2018 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dacap/7ddffbe401eb42620de397e47edfcc76 to your computer and use it in GitHub Desktop.
Save dacap/7ddffbe401eb42620de397e47edfcc76 to your computer and use it in GitHub Desktop.
Invalid RTTI with Clang on macOS (Apple LLVM version 9.1.0 (clang-902.0.39.1))
#include <cstdio>
#include <stdexcept>
int main() {
try {
throw std::runtime_error("test");
}
catch (const std::exception& e) {
// This catch block should be executed...
std::printf("%s exception\n", e.what());
}
catch (const std::runtime_error& e) {
// ...but instead we get this one when we link with "lib"
std::printf("%s runtime_error\n", e.what());
}
}
cmake_minimum_required(VERSION 3.0)
add_library(lib lib.cpp)
add_executable(app app.cpp)
target_link_libraries(app lib)
target_compile_options(app PRIVATE -frtti)
target_compile_options(lib PRIVATE -fno-rtti)
test runtime_error
#include <memory>
void fun1() {
// Comment this line and you will see the correct "test exception" output instead of "test runtime_error"
std::__throw_bad_weak_ptr();
}
void fun2() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment