}
virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
- ExprArg Throw) {
+ ExprArg Throw,
+ Scope *CurScope) {
llvm::cout << __FUNCTION__ << "\n";
return StmtEmpty();
}
"bad receiver type %0")
DIAG(warn_objc_throw_expects_object, WARNING,
"invalid %0 argument (expected an ObjC object type)")
+DIAG(error_rethrow_used_outside_catch, ERROR,
+ "‘@throw’ (rethrow) used outside of a @catch block")
// C++ casts
}
virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
- ExprArg Throw) {
+ ExprArg Throw,
+ Scope *CurScope) {
return StmtEmpty();
}
/// FunctionPrototypeScope - This is a scope that corresponds to the
/// parameters within a function prototype.
- FunctionPrototypeScope = 0x100
+ FunctionPrototypeScope = 0x100,
+
+ /// AtCatchScope - This is a scope that corresponds to the Objective-C
+ /// @catch statement.
+ AtCatchScope = 0x200
};
private:
/// The parent scope for this scope. This is null for the translation-unit
/// Flags - This contains a set of ScopeFlags, which indicates how the scope
/// interrelates with other control flow statements.
- unsigned Flags : 9;
+ unsigned Flags : 10;
/// WithinElse - Whether this scope is part of the "else" branch in
/// its parent ControlScope.
return getFlags() & Scope::FunctionPrototypeScope;
}
+ /// isAtCatchScope - Return true if this scope is @catch.
+ bool isAtCatchScope() const {
+ return getFlags() & Scope::AtCatchScope;
+ }
+
/// isWithinElse - Whether we are within the "else" of the
/// ControlParent (if any).
bool isWithinElse() const { return WithinElse; }
}
}
ConsumeToken(); // consume ';'
- return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res));
+ return Actions.ActOnObjCAtThrowStmt(atLoc, move(Res), CurScope);
}
/// objc-synchronized-statement:
ConsumeToken(); // consume catch
if (Tok.is(tok::l_paren)) {
ConsumeParen();
- ParseScope CatchScope(this, Scope::DeclScope);
+ ParseScope CatchScope(this, Scope::DeclScope|Scope::AtCatchScope);
if (Tok.isNot(tok::ellipsis)) {
DeclSpec DS;
ParseDeclarationSpecifiers(DS);
StmtArg Catch, StmtArg Finally);
virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
- ExprArg Throw);
+ ExprArg Throw,
+ Scope *CurScope);
virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
ExprArg SynchExpr,
StmtArg SynchBody);
}
Action::OwningStmtResult
-Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr) {
+Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr,
+ Scope *CurScope) {
Expr *ThrowExpr = static_cast<Expr*>(expr.release());
if (!ThrowExpr) {
- // FIXME: verify the 'rethrow' is within a @catch block
+ // @throw without an expression designates a rethrow (which much occur
+ // in the context of an @catch clause).
+ Scope *AtCatchParent = CurScope;
+ while (AtCatchParent && !AtCatchParent->isAtCatchScope())
+ AtCatchParent = AtCatchParent->getParent();
+ if (!AtCatchParent)
+ Diag(AtLoc, diag::error_rethrow_used_outside_catch);
} else {
QualType ThrowType = ThrowExpr->getType();
// Make sure the expression type is an ObjC pointer or "void *".
int foo() {
@throw 42; // expected-warning {{invalid 'int' argument (expected an ObjC object type)}}
- @throw; // FIXME: error: ‘@throw’ (rethrow) used outside of a @catch block
+ @throw; // expected-error {{‘@throw’ (rethrow) used outside of a @catch block}}
}