[cfe-commits] r56063 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/block-args.c
Steve Naroff
snaroff at apple.com
Wed Sep 10 11:33:01 PDT 2008
Author: snaroff
Date: Wed Sep 10 13:33:00 2008
New Revision: 56063
URL: http://llvm.org/viewvc/llvm-project?rev=56063&view=rev
Log:
Sema::ActOnIdentifierExpr(): Lookup block arguments.
Added:
cfe/trunk/test/Sema/block-args.c
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=56063&r1=56062&r2=56063&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 10 13:33:00 2008
@@ -354,7 +354,12 @@
return new PredefinedExpr(Loc, T, PredefinedExpr::ObjCSuper);
}
}
-
+ // If we are parsing a block, check the block parameter list.
+ if (CurBlock) {
+ for (unsigned i = 0, e = CurBlock->Params.size(); i != e; ++i)
+ if (CurBlock->Params[i]->getIdentifier() == &II)
+ D = CurBlock->Params[i];
+ }
if (D == 0) {
// Otherwise, this could be an implicitly declared function reference (legal
// in C90, extension in C99).
Added: cfe/trunk/test/Sema/block-args.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-args.c?rev=56063&view=auto
==============================================================================
--- cfe/trunk/test/Sema/block-args.c (added)
+++ cfe/trunk/test/Sema/block-args.c Wed Sep 10 13:33:00 2008
@@ -0,0 +1,24 @@
+// RUN: clang %s -fsyntax-only -verify
+
+void take(void*);
+
+void test() {
+ take(^(int x){});
+ take(^(int x, int y){});
+ take(^(int x, int y){});
+ take(^(int x, int x){}); // expected-error {{redefinition of parameter 'x'}}
+
+
+ take(^(int x) { return x+1; });
+
+ int (^CP)(int) = ^(int x) { return x*x; };
+ take(CP);
+
+ int arg;
+ ^{return 1;}();
+ ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
+ ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
+ ^(){return 4;}(arg); // C style (...), ok.
+ ^(int x, ...){return 5;}(arg, arg); // Explicit varargs, ok.
+}
+
More information about the cfe-commits
mailing list