]> granicus.if.org Git - clang/commitdiff
Add 'has_feature(cxx_exceptions)' to allow code to determine via preprocessor logic...
authorTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 01:34:15 +0000 (01:34 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 01:34:15 +0000 (01:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90378 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPMacroExpansion.cpp
test/Lexer/has_feature_exceptions.cpp [new file with mode: 0644]

index 6181e17e602d753d7fc9d75c0eb1399924263cf2..25f8b113c34de2a2dd5143890b6bf6ce93e60c9a 100644 (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;
diff --git a/test/Lexer/has_feature_exceptions.cpp b/test/Lexer/has_feature_exceptions.cpp
new file mode 100644 (file)
index 0000000..231a6c5
--- /dev/null
@@ -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