Last active
June 4, 2018 11:44
-
-
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))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test runtime_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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