2017-03-01 14:11:25 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -fblocks -Wno-objc-root-class -std=c++14 %s
2008-12-23 08:53:59 +08:00
@protocol NSObject;
void bar(id(^)(void));
void foo(id <NSObject>(^objectCreationBlock)(void)) {
2011-02-13 03:07:46 +08:00
return bar(objectCreationBlock); // OK
2008-12-23 08:53:59 +08:00
}
void bar2(id(*)(void));
void foo2(id <NSObject>(*objectCreationBlock)(void)) {
2010-12-03 05:47:04 +08:00
return bar2(objectCreationBlock); // expected-warning{{incompatible pointer types passing 'id<NSObject> (*)()' to parameter of type 'id (*)()'}}
2008-12-23 08:53:59 +08:00
}
2009-02-04 08:32:51 +08:00
void bar3(id(*)()); // expected-note{{candidate function}}
2008-12-23 08:53:59 +08:00
void foo3(id (*objectCreationBlock)(int)) {
2009-02-04 08:32:51 +08:00
return bar3(objectCreationBlock); // expected-error{{no matching}}
2008-12-23 08:53:59 +08:00
}
2009-02-04 08:32:51 +08:00
void bar4(id(^)()); // expected-note{{candidate function}}
2008-12-23 08:53:59 +08:00
void foo4(id (^objectCreationBlock)(int)) {
2009-02-04 08:32:51 +08:00
return bar4(objectCreationBlock); // expected-error{{no matching}}
2008-12-23 08:53:59 +08:00
}
void foo5(id (^x)(int)) {
if (x) { }
}
2009-02-17 03:28:42 +08:00
// <rdar://problem/6590445>
@interface Foo {
@private
void (^_block)(void);
}
- (void)bar;
@end
namespace N {
class X { };
void foo(X);
}
@implementation Foo
- (void)bar {
_block();
foo(N::X()); // okay
}
@end
2009-12-12 06:40:48 +08:00
typedef signed char BOOL;
void foo6(void *block) {
void (^vb)(id obj, int idx, BOOL *stop) = (void (^)(id, int, BOOL *))block;
BOOL (^bb)(id obj, int idx, BOOL *stop) = (BOOL (^)(id, int, BOOL *))block;
}
2010-11-02 02:37:59 +08:00
// <rdar://problem/8600419>: Require that the types of block
// parameters are complete.
namespace N1 {
template<class _T> class ptr; // expected-note{{template is declared here}}
template<class _T>
class foo {
public:
void bar(void (^)(ptr<_T>));
};
class X;
void test2();
void test()
{
foo<X> f;
f.bar(^(ptr<X> _f) { // expected-error{{implicit instantiation of undefined template 'N1::ptr<N1::X>'}}
test2();
});
}
}
2011-01-19 19:48:09 +08:00
// Make sure we successfully instantiate the copy constructor of a
2018-10-02 05:51:28 +08:00
// __block variable's type when the variable is captured by an escaping block.
2011-01-19 19:48:09 +08:00
namespace N2 {
template <int n> struct A {
A() {}
A(const A &other) {
int invalid[-n]; // expected-error 2 {{array with a negative size}}
}
2018-10-02 05:51:28 +08:00
void m() {}
2011-01-19 19:48:09 +08:00
};
2018-10-02 05:51:28 +08:00
typedef void (^BlockFnTy)();
void func(BlockFnTy);
2011-01-19 19:48:09 +08:00
void test1() {
__block A<1> x; // expected-note {{requested here}}
2018-10-02 05:51:28 +08:00
func(^{ x.m(); });
2011-01-19 19:48:09 +08:00
}
template <int n> void test2() {
__block A<n> x; // expected-note {{requested here}}
2018-10-02 05:51:28 +08:00
func(^{ x.m(); });
2011-01-19 19:48:09 +08:00
}
template void test2<2>();
}
2011-01-20 05:52:31 +08:00
// Handle value-dependent block declaration references.
namespace N3 {
template<int N> struct X { };
template<int N>
void f() {
X<N> xN = ^() { return X<N>(); }();
}
}
2011-02-13 03:07:46 +08:00
// rdar://8979379
@interface A
@end
@interface B : A
@end
void f(int (^bl)(A* a)); // expected-note {{candidate function not viable: no known conversion from 'int (^)(B *)' to 'int (^)(A *)' for 1st argument}}
void g() {
f(^(B* b) { return 0; }); // expected-error {{no matching function for call to 'f'}}
}
2011-06-05 13:14:41 +08:00
namespace DependentReturn {
template<typename T>
void f(T t) {
(void)^(T u) {
if (t != u)
return t + u;
else
return;
};
(void)^(T u) {
if (t == u)
return;
else
return t + u;
};
}
struct X { };
void operator+(X, X);
bool operator==(X, X);
bool operator!=(X, X);
template void f<X>(X);
}
2017-02-15 13:15:28 +08:00
2017-03-01 14:11:25 +08:00
namespace GenericLambdaCapture {
int test(int outerp) {
auto lambda =[&](auto p) {
return ^{
return p + outerp;
}();
};
return lambda(1);
}
}
2017-02-15 13:15:28 +08:00
namespace MoveBlockVariable {
struct B0 {
};
struct B1 { // expected-note 2 {{candidate constructor (the implicit}}
B1(B0&&); // expected-note {{candidate constructor not viable}}
};
B1 test_move() {
__block B0 b;
return b; // expected-error {{no viable conversion from returned value of type 'MoveBlockVariable::B0' to function return type 'MoveBlockVariable::B1'}}
}
}