1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 %s -fsyntax-only -verify -fblocks
21f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
31f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroffvoid take(void*);
41f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
51f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroffvoid test() {
61f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  take(^(int x){});
71f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  take(^(int x, int y){});
81f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  take(^(int x, int y){});
9d84aac17180075e0ede53d7762b73d3bd079b52fChris Lattner  take(^(int x,      // expected-note {{previous declaration is here}}
10d84aac17180075e0ede53d7762b73d3bd079b52fChris Lattner         int x){});  // expected-error {{redefinition of parameter 'x'}}
111f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
121f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
131f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  take(^(int x) { return x+1; });
141f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
151f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  int (^CP)(int) = ^(int x) { return x*x; };
161f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  take(CP);
171f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
181f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  int arg;
191f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  ^{return 1;}();
201f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  ^{return 2;}(arg); // expected-error {{too many arguments to block call}}
211f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  ^(void){return 3;}(1); // expected-error {{too many arguments to block call}}
22687abffee40d0459fe5eecf3e5ee6e60be69d93cEli Friedman  ^(){return 4;}(arg); // expected-error {{too many arguments to block call}}
231f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff  ^(int x, ...){return 5;}(arg, arg);   // Explicit varargs, ok.
241f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff}
251f3b0d5ccabbc47aef525baec10c15d9fd1c6236Steve Naroff
2613591ed054d1b2d6d392151ba05cbc883e640648John McCallint main(int argc, char** argv) {
27ae530cfaf65e36fdcecb16d072422eb3d2a4518eSteve Naroff  ^(int argCount) {
28ae530cfaf65e36fdcecb16d072422eb3d2a4518eSteve Naroff    argCount = 3;
29ae530cfaf65e36fdcecb16d072422eb3d2a4518eSteve Naroff  }(argc);
30ae530cfaf65e36fdcecb16d072422eb3d2a4518eSteve Naroff}
319a66c303c7024967a48877106384bf315c84e80eFariborz Jahanian
329a66c303c7024967a48877106384bf315c84e80eFariborz Jahanian// radar 7528255
339a66c303c7024967a48877106384bf315c84e80eFariborz Jahanianvoid f0() {
349a66c303c7024967a48877106384bf315c84e80eFariborz Jahanian  ^(int, double d, char) {}(1, 1.34, 'a'); // expected-error {{parameter name omitted}} \
359a66c303c7024967a48877106384bf315c84e80eFariborz Jahanian				 	   // expected-error {{parameter name omitted}}
369a66c303c7024967a48877106384bf315c84e80eFariborz Jahanian}
37da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall
38da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall// rdar://problem/8962770
39da263795abd39437d73d23fcf34dcd3afc1d7df3John McCallvoid test4() {
40da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall  int (^f)() = ^((x)) { }; // expected-error {{expected ')'}} expected-warning {{type specifier missing}} expected-note {{to match this}}
41da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall}
42da263795abd39437d73d23fcf34dcd3afc1d7df3John McCall
434f38f414b8676ea43439d6ad3315e32042d315cbJohn McCall// rdar://problem/9170609
444f38f414b8676ea43439d6ad3315e32042d315cbJohn McCallvoid test5_helper(void (^)(int, int[*]));
454f38f414b8676ea43439d6ad3315e32042d315cbJohn McCallvoid test5(void) {
464f38f414b8676ea43439d6ad3315e32042d315cbJohn McCall  test5_helper(^(int n, int array[n]) {});
474f38f414b8676ea43439d6ad3315e32042d315cbJohn McCall}
489808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner
499808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner// Reduced from a problem on platforms where va_list is an array.
509808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Klecknerstruct tag {
519808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner  int x;
529808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner};
539808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Klecknertypedef struct tag array_ty[1];
549808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Klecknervoid test6(void) {
559808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner  void (^block)(array_ty) = ^(array_ty arr) { };
569808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner  array_ty arr;
579808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner  block(arr);
589808b711aa2153e4fe9a627a2721fa5c3bbbdc97Reid Kleckner}
59