From 5ef26fb4fd9d6a3ac7b35eb5f3a2a4814449a28f Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 3 Dec 2009 01:34:15 +0000 Subject: [PATCH] Add 'has_feature(cxx_exceptions)' to allow code to determine via preprocessor logic if C++ exceptions are enabled. llvm-svn: 90378 --- clang/lib/Lex/PPMacroExpansion.cpp | 3 +++ clang/test/Lexer/has_feature_exceptions.cpp | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 clang/test/Lexer/has_feature_exceptions.cpp diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 6181e17e602d..25f8b113c34d 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/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/clang/test/Lexer/has_feature_exceptions.cpp b/clang/test/Lexer/has_feature_exceptions.cpp new file mode 100644 index 000000000000..231a6c56a45b --- /dev/null +++ b/clang/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