<div dir="ltr">Unfortunately, there is no description for -fno-rtti flag on <br><a href="https://releases.llvm.org/11.0.0/tools/clang/docs/ClangCommandLineReference.html">https://releases.llvm.org/11.0.0/tools/clang/docs/ClangCommandLineReference.html</a> but I assume it should work the same as in GCC:<br>> Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (`dynamic_cast' and `typeid'). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed.<br><br>So it looks like in G++ we can use -fno-rtti, but the compiler will still generate it if needed. Is it true for Clang on macOS? If not, then what about Linux?<br><br>I also found the -fno-rtti-data option, without description as well.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 26, 2021 at 6:44 PM Marshall Clow <<a href="mailto:mclow.lists@gmail.com">mclow.lists@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div>[ removing cfe-dev]</div><div><br></div>On Jan 26, 2021, at 7:25 AM, Ilia K via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<br><div><blockquote type="cite"><br><div><div dir="ltr">Hi!<br><br>It turned out that I cannot catch `std::bad_alloc&` thrown by the `operator new` when compiling 1.cpp with -fno-rtti and linking against system's libc++.1.dylib/libc++abi.dylib on macOS. This scenario works on Linux, and according to the official libc++ page it is supported ("However linking against it with -fno-rtti is supported", <a href="https://libcxx.llvm.org/" target="_blank">https://libcxx.llvm.org/</a>), however the following code is aborted due to an unhandled exception:<br><br>```1.cpp<br>#include <cstdio><br>#include <new><br><br>int main() {<br>    try {<br>        ::operator new(-1);<br>    } catch (std::bad_alloc& e) {<br>        printf("caught %s\n", e.what());<br>    }<br>    return 0;<br>}<br>```<br><br>Compile & run:<br>```<br>$ clang++ -fno-rtti 1.cpp -o 1_no_rtti<br>$ ./1_no_rtti<br>libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc<br>Abort trap: 6<br>```<br></div></div></blockquote><div><br></div><div><br></div>That sounds right to me.</div><div>If you don’t have RTTI, then the catch mechanism cannot match up the type of the exception and the type that you’re looking to catch.</div><div>You should be able to catch (…), though.</div><div><br></div><div>— Marshall</div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">- Ilia</div></div>