]> granicus.if.org Git - clang/commitdiff
Disallow try/catch/throw when exceptions are disabled.
authorAnders Carlsson <andersca@mac.com>
Sat, 19 Feb 2011 19:26:44 +0000 (19:26 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 19 Feb 2011 19:26:44 +0000 (19:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126039 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaStmt.cpp
test/SemaCXX/no-exceptions.cpp

index 4560f6e9a34cf9e439189b2e1e88e9b79f83d904..8306eb490f64d8daed2c88d0187764f78ab0170b 100644 (file)
@@ -2823,6 +2823,8 @@ def err_bad_memptr_lhs : Error<
 def warn_exception_caught_by_earlier_handler : Warning<
   "exception of type %0 will be caught by earlier handler">;
 def note_previous_exception_handler : Note<"for type %0">;
+def err_exceptions_disabled : Error<
+  "cannot use '%0' with exceptions disabled">;
 def warn_non_virtual_dtor : Warning<
   "%0 has virtual functions but non-virtual destructor">,
   InGroup<NonVirtualDtor>, DefaultIgnore;
index 9113f8a4621eb0a2014549fa400e1a8dcfa55ae2..07e6b6f14b1f8e20e24bc72fb1d534f14dd670e4 100644 (file)
@@ -476,6 +476,9 @@ Sema::ActOnCXXNullPtrLiteral(SourceLocation Loc) {
 /// ActOnCXXThrow - Parse throw expressions.
 ExprResult
 Sema::ActOnCXXThrow(SourceLocation OpLoc, Expr *Ex) {
+  if (!getLangOptions().Exceptions)
+    return Diag(OpLoc, diag::err_exceptions_disabled) << "throw";
+
   if (Ex && !Ex->isTypeDependent() && CheckCXXThrowOperand(OpLoc, Ex))
     return ExprError();
   return Owned(new (Context) CXXThrowExpr(Ex, Context.VoidTy, OpLoc));
index ba50824c1bdac6059643f721aa11ec26cc4b9b41..523fc4a852c4c4f8fa42a3c1f5c0cfdcac8ad343 100644 (file)
@@ -1741,6 +1741,9 @@ public:
 StmtResult
 Sema::ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock,
                        MultiStmtArg RawHandlers) {
+  if (!getLangOptions().Exceptions)
+    return Diag(TryLoc, diag::err_exceptions_disabled) << "try";
+
   unsigned NumHandlers = RawHandlers.size();
   assert(NumHandlers > 0 &&
          "The parser shouldn't call this if there are no handlers.");
index 019e25c978422402ab6dffd4e0ee38c946bf0d50..f7395683c3f5d65109348af0323d55f79cef0524 100644 (file)
@@ -19,3 +19,17 @@ namespace test0 {
     (void) new Foo();
   }
 }
+
+namespace test1 {
+void f() {
+  throw; // expected-error {{cannot use 'throw' with exceptions disabled}}
+}
+
+void g() {
+  try { // expected-error {{cannot use 'try' with exceptions disabled}}
+    f();
+  } catch (...) {
+  }
+}
+
+}