]> granicus.if.org Git - clang/commitdiff
Statement expressions can be used in global- or namespace-scoped blocks
authorDouglas Gregor <dgregor@apple.com>
Wed, 10 Mar 2010 04:54:39 +0000 (04:54 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 10 Mar 2010 04:54:39 +0000 (04:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98135 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjC/exprs.m

index 10001c356d1cb257462ccc79d5a0fb2f7b5dd89c..2249579ba4e1aa99700a8bd43b8aa764b9d9d54e 100644 (file)
@@ -6593,7 +6593,8 @@ Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtArg substmt,
   assert(SubStmt && isa<CompoundStmt>(SubStmt) && "Invalid action invocation!");
   CompoundStmt *Compound = cast<CompoundStmt>(SubStmt);
 
-  bool isFileScope = getCurFunctionOrMethodDecl() == 0;
+  bool isFileScope
+    = (getCurFunctionOrMethodDecl() == 0) && (getCurBlock() == 0);
   if (isFileScope)
     return ExprError(Diag(LPLoc, diag::err_stmtexpr_file_scope));
 
index 33b144461f2b28e24a4b3a59d14c6abb68cc77a1..3370bda0517af8dcacf7fbf633aff86e6d01a15f 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -fsyntax-only -verify -Wno-unreachable-code
+// RUN: %clang_cc1 %s -fsyntax-only -fblocks -verify -Wno-unreachable-code
 
 // rdar://6597252
 Class test1(Class X) {
@@ -19,3 +19,6 @@ void test2() {
   
   if (@encode(int) == "foo") { }  // expected-warning {{result of comparison against @encode is unspecified}}
 }
+
+#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
+void (^foo)(int, int) = ^(int x, int y) { int z = MAX(x, y); };