1 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++11 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -fblocks -std=c++1z %s
4 typedef void (^BlockTy)();
11 void escapingFunc0(BlockTy);
12 void noescapeFunc0(id, __attribute__((noescape)) BlockTy);
13 void noescapeFunc1(id, [[clang::noescape]] BlockTy);
14 void noescapeFunc2(__attribute__((noescape)) int *); // expected-note {{previous declaration is here}}
15 void noescapeFunc3(__attribute__((noescape)) id);
16 void noescapeFunc4(__attribute__((noescape)) int &);
17 void noescapeFunc2(int *); // expected-error {{conflicting types for 'noescapeFunc2'}}
20 void noescapeFunc5(__attribute__((noescape)) T);
22 void noescapeFunc6(__attribute__((noescape)) const T &);
24 void noescapeFunc7(__attribute__((noescape)) T &&);
26 void invalidFunc0(int __attribute__((noescape))); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
27 void invalidFunc1(int __attribute__((noescape(0)))); // expected-error {{'noescape' attribute takes no arguments}}
28 void invalidFunc2(int0 *__attribute__((noescape))); // expected-error {{use of undeclared identifier 'int0'; did you mean 'int'?}}
29 void invalidFunc3(__attribute__((noescape)) int (S::*Ty)); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
30 void invalidFunc4(__attribute__((noescape)) void (S::*Ty)()); // expected-warning {{'noescape' attribute only applies to pointer arguments}}
31 int __attribute__((noescape)) g; // expected-warning {{'noescape' attribute only applies to parameters}}
34 virtual void m0(int *__attribute__((noescape))); // expected-note {{parameter of overridden method is annotated with __attribute__((noescape))}}
38 void m0(int *__attribute__((noescape))) override;
42 void m0(int *) override; // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
45 __attribute__((objc_root_class))
47 -(void) m0:(int*)__attribute__((noescape)) p; // expected-note {{parameter of overridden method is annotated with __attribute__((noescape))}}
48 - (void)noescapeLValRefParam:(const BlockTy &)__attribute__((noescape))p;
49 - (void)noescapeRValRefParam:(BlockTy &&)__attribute__((noescape))p;
53 -(void) m0:(int*)__attribute__((noescape)) p {}
54 - (void)noescapeLValRefParam:(const BlockTy &)__attribute__((noescape))p {
56 - (void)noescapeRValRefParam:(BlockTy &&)__attribute__((noescape))p {
61 -(void) m0:(int*)__attribute__((noescape)) p;
64 @implementation C1 : C0
65 -(void) m0:(int*)__attribute__((noescape)) p {}
69 -(void) m0:(int*) p; // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
72 @implementation C2 : C0
73 -(void) m0:(int*) p {}
77 void (*fnptr0)(int *);
78 void (*fnptr1)(__attribute__((noescape)) int *);
79 template<void (*fn)(int*)> struct S4 {};
80 template<void (*fn)(int* __attribute__((noescape)))> struct S5 {};
82 #if __cplusplus < 201406
83 // expected-note@-4 {{template parameter is declared here}}
84 // expected-note@-4 {{template parameter is declared here}}
89 fnptr0 = &noescapeFunc2;
90 fnptr1 = &func0; // expected-error {{incompatible function pointer types assigning to 'void (*)(__attribute__((noescape)) int *)' from 'void (*)(int *)'}}
91 fnptr1 = &noescapeFunc2;
93 S4<&noescapeFunc2> e1;
96 #if __cplusplus < 201406
97 // expected-error@-4 {{non-type template argument of type 'void (*)(__attribute__((noescape)) int *)' cannot be converted to a value of type 'void (*)(int *)'}}
98 // expected-error@-4 {{non-type template argument of type 'void (*)(int *)' cannot be converted to a value of type 'void (*)(__attribute__((noescape)) int *)'}}
100 // expected-error@-6 {{value of type 'void (*)(int *)' is not implicitly convertible to 'void (*)(__attribute__((noescape)) int *)'}}
103 S5<&noescapeFunc2> ne1;
106 @protocol NoescapeProt
107 -(void) m0:(int*)__attribute__((noescape)) p; // expected-note 2 {{parameter of overridden method is annotated with __attribute__((noescape))}}
108 +(void) m1:(int*)__attribute__((noescape)) p;
112 __attribute__((objc_root_class))
115 +(void) m1:(int*)__attribute__((noescape)) p;
119 @interface C3 () <NoescapeProt> // expected-note {{class extension conforms to protocol 'NoescapeProt' which defines method 'm0:'}}
123 -(void) m0:(int*) p { // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
125 +(void) m1:(int*)__attribute__((noescape)) p {
127 -(void) m1:(int*) p {
131 __attribute__((objc_root_class))
132 @interface C4 <NoescapeProt>
133 -(void) m0:(int*) p; // expected-warning {{parameter of overriding method should be annotated with __attribute__((noescape))}}
137 -(void) m0:(int*) p {
139 +(void) m1:(int*)__attribute__((noescape)) p {
141 -(void) m1:(int*) p {
147 S6(const S6 &) = delete; // expected-note 11 {{'S6' has been explicitly marked deleted here}}
153 // __block variables that are not captured by escaping blocks don't
154 // necessitate having accessible copy constructors.
156 __block S6 b1; // expected-error {{call to deleted constructor of 'S6'}}
157 __block S6 b2; // expected-error {{call to deleted constructor of 'S6'}}
158 __block S6 b3; // expected-error {{call to deleted constructor of 'S6'}}
159 __block S6 b4; // expected-error {{call to deleted constructor of 'S6'}}
160 __block S6 b5; // expected-error {{call to deleted constructor of 'S6'}}
161 __block S6 b6; // expected-error {{call to deleted constructor of 'S6'}}
162 __block S6 b7; // expected-error {{call to deleted constructor of 'S6'}}
163 __block S6 b8; // expected-error {{call to deleted constructor of 'S6'}}
165 __block S6 b10; // expected-error {{call to deleted constructor of 'S6'}}
166 __block S6 b11; // expected-error {{call to deleted constructor of 'S6'}}
169 __block S6 b14; // expected-error {{call to deleted constructor of 'S6'}}
171 noescapeFunc0(a, ^{ (void)b0; });
172 escapingFunc0(^{ (void)b1; });
174 noescapeFunc0(a, ^{ (void)b0; (void)b1; });
176 noescapeFunc0(a, ^{ escapingFunc0(^{ (void)b2; }); });
177 escapingFunc0(^{ noescapeFunc0(a, ^{ (void)b3; }); });
179 [c0 noescapeLValRefParam:^{
183 [c0 noescapeRValRefParam:^{
187 void noescape_id(__attribute__((noescape)) id);
192 void noescapeLValRefParam(__attribute__((noescape)) const BlockTy &);
193 noescapeLValRefParam(^{
197 void noescapeRValRefParam(__attribute__((noescape)) BlockTy &&);
198 noescapeRValRefParam(^{
214 struct NoescapeCtor {
215 NoescapeCtor(__attribute__((noescape)) void (^)());
218 EscapeCtor(void (^)());
221 void helper1(NoescapeCtor a);
226 void helper2(NoescapeCtor && a);
231 void helper3(__attribute__((noescape)) EscapeCtor && a);