diff options
author | Anders Carlsson <andersca@mac.com> | 2011-02-19 19:26:44 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-02-19 19:26:44 +0000 |
commit | 7f11d9cf5df1f8ce82af46eabc4ec5cec7d580b0 (patch) | |
tree | a870ff25e6a7304d663f1a819110a41bb3e8c769 | |
parent | d9ea180032eda76a46c099a9aab99512447c326d (diff) |
Disallow try/catch/throw when exceptions are disabled.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126039 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/no-exceptions.cpp | 14 |
4 files changed, 22 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 4560f6e9a3..8306eb490f 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 9113f8a462..07e6b6f14b 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -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)); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index ba50824c1b..523fc4a852 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -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."); diff --git a/test/SemaCXX/no-exceptions.cpp b/test/SemaCXX/no-exceptions.cpp index 019e25c978..f7395683c3 100644 --- a/test/SemaCXX/no-exceptions.cpp +++ b/test/SemaCXX/no-exceptions.cpp @@ -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 (...) { + } +} + +} |