Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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"
void fun2() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment