Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect at compile time whether exceptions are disabled [duplicate]

Tags:

c++

exception

I'm trying to detect at compile time whether exceptions have been disabled with the (-fno-exceptions) switch. I've tried to evaluate:

noexcept(throw)

But this won't compile if the exceptions are disabled under both gcc and clang.

EDIT: Take a look here.

like image 249
user1095108 Avatar asked Dec 14 '22 08:12

user1095108


1 Answers

As always, it's fairly easy to check which macros are pre-defined for a particular compiler with a given set of command line parameters:

$ g++ -dM -E -x c++ - < /dev/null &> except.txt
$ g++ -dM -E -x c++ -fno-exceptions - < /dev/null &> no-except.txt
$ sdiff -s except.txt no-except.txt 
#define __EXCEPTIONS 1                            <
#define __cpp_exceptions 199711                   <
$
like image 129
Paul R Avatar answered Dec 29 '22 01:12

Paul R