forked from OSchip/llvm-project
Disallow try/catch/throw when exceptions are disabled.
llvm-svn: 126039
This commit is contained in:
parent
bf2b26d805
commit
68b36aff46
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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 (...) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue