Add 'has_feature(cxx_exceptions)' to allow code to determine via preprocessor logic if C++ exceptions are enabled.

llvm-svn: 90378
This commit is contained in:
Ted Kremenek 2009-12-03 01:34:15 +00:00
parent 26ada867ba
commit 5ef26fb4fd
2 changed files with 14 additions and 0 deletions

View File

@ -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;

View File

@ -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