From: Ted Kremenek Date: Thu, 3 Dec 2009 01:34:15 +0000 (+0000) Subject: Add 'has_feature(cxx_exceptions)' to allow code to determine via preprocessor logic... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7d9bd4257f817494b2fa5b310df05807050a9c18;p=clang Add 'has_feature(cxx_exceptions)' to allow code to determine via preprocessor logic if C++ exceptions are enabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90378 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 6181e17e60..25f8b113c3 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -488,6 +488,9 @@ static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II) { return false; case 8: if (II->isStr("cxx_rtti")) return LangOpts.RTTI; + return false; + case 14: + if (II->isStr("cxx_exceptions")) return LangOpts.Exceptions; return false; case 19: if (II->isStr("objc_nonfragile_abi")) return LangOpts.ObjCNonFragileABI; diff --git a/test/Lexer/has_feature_exceptions.cpp b/test/Lexer/has_feature_exceptions.cpp new file mode 100644 index 0000000000..231a6c56a4 --- /dev/null +++ b/test/Lexer/has_feature_exceptions.cpp @@ -0,0 +1,11 @@ +// RUN: clang -E -fexceptions %s -o - | FileCheck --check-prefix=CHECK-EXCEPTIONS %s +// RUN: clang -E -fno-exceptions %s -o - | FileCheck --check-prefix=CHECK-NO-EXCEPTIONS %s + +#if __has_feature(cxx_exceptions) +int foo(); +#else +int bar(); +#endif + +// CHECK-EXCEPTIONS: foo +// CHECK-NO-EXCEPTIONS: bar