[cfe-commits] r126039 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprCXX.cpp lib/Sema/SemaStmt.cpp test/SemaCXX/no-exceptions.cpp

Anders Carlsson andersca at mac.com
Sat Feb 19 11:26:45 PST 2011


Author: andersca
Date: Sat Feb 19 13:26:44 2011
New Revision: 126039

URL: http://llvm.org/viewvc/llvm-project?rev=126039&view=rev
Log:
Disallow try/catch/throw when exceptions are disabled.

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=126039&r1=126038&r2=126039&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Feb 19 13:26:44 2011
@@ -2823,6 +2823,8 @@
 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;

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=126039&r1=126038&r2=126039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Feb 19 13:26:44 2011
@@ -476,6 +476,9 @@
 /// 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));

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=126039&r1=126038&r2=126039&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Feb 19 13:26:44 2011
@@ -1741,6 +1741,9 @@
 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.");

Modified: cfe/trunk/test/SemaCXX/no-exceptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/no-exceptions.cpp?rev=126039&r1=126038&r2=126039&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/no-exceptions.cpp (original)
+++ cfe/trunk/test/SemaCXX/no-exceptions.cpp Sat Feb 19 13:26:44 2011
@@ -19,3 +19,17 @@
     (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 (...) {
+  }
+}
+
+}





More information about the cfe-commits mailing list