// Blocks
+def err_blocks_disable : Error<"blocks support disabled - compile with -fblocks"
+ " or pick a deployment target that supports them">;
def err_expected_block_lbrace : Error<"expected '{' in block literal">;
def err_goto_in_block : Error<
"goto not allowed in block literal">;
tok::TokenKind Kind = Tok.getKind();
// Not a pointer, C++ reference, or block.
- if (Kind != tok::star &&
+ if (Kind != tok::star && Kind != tok::caret &&
(Kind != tok::amp || !getLang().CPlusPlus) &&
// We parse rvalue refs in C++03, because otherwise the errors are scary.
- (Kind != tok::ampamp || !getLang().CPlusPlus) &&
- (Kind != tok::caret || !getLang().Blocks)) {
+ (Kind != tok::ampamp || !getLang().CPlusPlus)) {
if (DirectDeclParser)
(this->*DirectDeclParser)(D);
return;
SourceLocation Loc = ConsumeToken(); // Eat the *, ^, & or &&.
D.SetRangeEnd(Loc);
- if (Kind == tok::star || (Kind == tok::caret && getLang().Blocks)) {
+ if (Kind == tok::star || Kind == tok::caret) {
// Is a pointer.
DeclSpec DS;
return ParseObjCAtExpression(AtLoc);
}
case tok::caret:
- if (getLang().Blocks)
- return ParsePostfixExpressionSuffix(ParseBlockLiteralExpression());
- Diag(Tok, diag::err_expected_expression);
- return ExprError();
+ return ParsePostfixExpressionSuffix(ParseBlockLiteralExpression());
case tok::l_square:
// These can be followed by postfix-expr pieces.
if (getLang().ObjC1)
OwningExprResult Result(Actions, true);
- if (Tok.is(tok::l_brace)) {
- OwningStmtResult Stmt(ParseCompoundStatementBody());
- if (!Stmt.isInvalid()) {
- Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope);
- } else {
- Actions.ActOnBlockError(CaretLoc, CurScope);
- }
- } else {
+ if (!Tok.is(tok::l_brace)) {
// Saw something like: ^expr
Diag(Tok, diag::err_expected_expression);
return ExprError();
}
+
+ OwningStmtResult Stmt(ParseCompoundStatementBody());
+ if (!Stmt.isInvalid())
+ Result = Actions.ActOnBlockStmtExpr(CaretLoc, move(Stmt), CurScope);
+ else
+ Actions.ActOnBlockError(CaretLoc, CurScope);
return move(Result);
}
if (Tok.is(tok::coloncolon) || Tok.is(tok::identifier))
TryAnnotateCXXScopeToken();
- if (Tok.is(tok::star) || Tok.is(tok::amp) ||
- (Tok.is(tok::caret) && getLang().Blocks) ||
+ if (Tok.is(tok::star) || Tok.is(tok::amp) || Tok.is(tok::caret) ||
(Tok.is(tok::annot_cxxscope) && NextToken().is(tok::star))) {
// ptr-operator
ConsumeToken();
while (Tok.is(tok::kw_const) ||
Tok.is(tok::kw_volatile) ||
- Tok.is(tok::kw_restrict) )
+ Tok.is(tok::kw_restrict))
ConsumeToken();
} else {
break;
/// literal was successfully completed. ^(int x){...}
Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc,
StmtArg body, Scope *CurScope) {
+ // If blocks are disabled, emit an error.
+ if (!LangOpts.Blocks)
+ Diag(CaretLoc, diag::err_blocks_disable);
+
// Ensure that CurBlock is deleted.
llvm::OwningPtr<BlockSemaInfo> BSI(CurBlock);
switch (DeclType.Kind) {
default: assert(0 && "Unknown decltype!");
case DeclaratorChunk::BlockPointer:
+ // If blocks are disabled, emit an error.
+ if (!LangOpts.Blocks)
+ Diag(DeclType.Loc, diag::err_blocks_disable);
+
if (DeclType.Cls.TypeQuals)
Diag(D.getIdentifierLoc(), diag::err_qualified_block_pointer_type);
if (!T.getTypePtr()->isFunctionType())
-// RUN: clang-cc %s -verify -pedantic -fsyntax-only
+// RUN: clang-cc %s -verify -pedantic -fsyntax-only -fno-blocks
// PR1966
_Complex double test1() {
return X == "foo"; // expected-warning {{comparison against a string literal is unspecified}}
}
+// rdar://6719156
+void test13(
+ void (^P)()) { // expected-error {{blocks support disabled - compile with -fblocks}}
+ P();
+ P = ^(){}; // expected-error {{blocks support disabled - compile with -fblocks}}
+}