1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class -std=c++14 %s
5 void foo(id <NSObject>(^objectCreationBlock)(void)) {
6 return bar(objectCreationBlock); // OK
9 void bar2(id(*)(void));
10 void foo2(id <NSObject>(*objectCreationBlock)(void)) {
11 return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id<NSObject> (*)()' to parameter of type 'id (*)()'}}
14 void bar3(id(*)()); // expected-note{{candidate function}}
15 void foo3(id (*objectCreationBlock)(int)) {
16 return bar3(objectCreationBlock); // expected-error{{no matching}}
19 void bar4(id(^)()); // expected-note{{candidate function}}
20 void foo4(id (^objectCreationBlock)(int)) {
21 return bar4(objectCreationBlock); // expected-error{{no matching}}
24 void foo5(id (^x)(int)) {
47 typedef signed char BOOL;
48 void foo6(void *block) {
49 void (^vb)(id obj, int idx, BOOL *stop) = (void (^)(id, int, BOOL *))block;
50 BOOL (^bb)(id obj, int idx, BOOL *stop) = (BOOL (^)(id, int, BOOL *))block;
53 // Require that the types of block parameters are complete.
55 template<class _T> class ptr; // expected-note{{template is declared here}}
60 void bar(void (^)(ptr<_T>));
70 f.bar(^(ptr<X> _f) { // expected-error{{implicit instantiation of undefined template 'N1::ptr<N1::X>'}}
76 // Make sure we successfully instantiate the copy constructor of a
77 // __block variable's type when the variable is captured by an escaping block.
79 template <int n> struct A {
82 int invalid[-n]; // expected-error 2 {{array with a negative size}}
87 typedef void (^BlockFnTy)();
91 __block A<1> x; // expected-note {{requested here}}
95 template <int n> void test2() {
96 __block A<n> x; // expected-note {{requested here}}
99 template void test2<2>();
102 // Handle value-dependent block declaration references.
104 template<int N> struct X { };
108 X<N> xN = ^() { return X<N>(); }();
118 void f(int (^bl)(A* a)); // expected-note {{candidate function not viable: no known conversion from 'int (^)(B *)' to 'int (^)(A *)' for 1st argument}}
121 f(^(B* b) { return 0; }); // expected-error {{no matching function for call to 'f'}}
124 namespace DependentReturn {
143 void operator+(X, X);
144 bool operator==(X, X);
145 bool operator!=(X, X);
147 template void f<X>(X);
150 namespace GenericLambdaCapture {
151 int test(int outerp) {
152 auto lambda =[&](auto p) {
161 namespace MoveBlockVariable {
165 struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
166 B1(B0&&); // expected-note {{candidate constructor not viable}}
171 return b; // expected-error {{no viable conversion from returned value of type 'B0' to function return type 'B1'}}