Using STD exceptions in Clang code


I am programming a little code rewriter using Clang libraries, and I need to catch an std::out_of_range exception to break the execution of a loop. When I try to compile the code, despite using the flag “-fexception”, gcc tells me that the exception handling disabled, so I must use -fexceptions to enable it.

I also tried to copy this piece of code into another C++ file (not depending on Clang libraries) and to compile it, and then it works with no problem.

Anyone can help me? Thank you very much!

PS: Sorry for my bad english, i’m not used to write this kind of messages. And it’s also my first message sent to the list…

You may be affected by the fact that the clang libraries themselves (the ones
you are using), are built by default with exceptions disabled. If you are throwing
"through" these libraries there would be an issue since cleanups would need to
be invoked (internal to the clang libraries). If this is the case, you can always
rebuild clang/llvm with exceptions on. Beyond a performance hit, I'm not sure
what the stability issues would be when using clang/llvm built with exceptions

Hope this helps


Mostly, it's that we don't write exceptions-safe code. We do like
RAII, and you probably won't get memory leaks if you throw through
LLVM or clang code, but we've made absolutely no effort to support this.