This file compiles without error when using -fno-exceptions: extern int f2(); template<typename T> void f1() { try { f2(); } catch (...) { } } Compiling this very similar file: extern int f2(); template<typename T> void f1() { try { f2(); } catch (...) { } } template f1<int>(); gives these errors: foo.cc: In function ‘void f1() [with T = int]’: foo.cc:6: instantiated from here foo.cc:4: error: exception handling disabled, use -fexceptions to enable I think it would be more consistent for g++ to reject uses of try/catch when compiling with -fno-exceptions even in uninstantiated templates. Otherwise you can get surprising results when code changes: you can find problems in very different pieces of code.
I'm not sure. What about extern int f2(); struct NoExcept {}; template<typename T> void f1() { try { f2(); } catch (...) { } } template<> void f1<NoExcept>() { f2(); } template f1<NoExcept>(); ? EH code could be disabled by some tags and specialization. Especially for a library that has a non-exception variant that would sound useful.
IIRC this was done on purpose but I cannot find the original discussion.