Debian Codegraph @

clang/test/SemaObjC/nullable-result.m

raw
1 // RUN: %clang_cc1 -verify -fsyntax-only -fblocks -Wnullable-to-nonnull-conversion %s
2 // RUN: %clang_cc1 -xobjective-c++ -verify -fsyntax-only -fblocks -Wnullable-to-nonnull-conversion %s
3
4 @class X;
5 @class NSError;
6
7 _Static_assert(__has_feature(nullability_nullable_result), "");
8
9 @interface SomeClass
10 -(void)async_get:(void (^)(X *_Nullable_result rptr, NSError *err))completionHandler;
11 @end
12
13 void call(SomeClass *sc) {
14 [sc async_get:^(X *_Nullable_result rptr, NSError *err) {}];
15 [sc async_get:^(X *_Nullable rptr, NSError *err) {}];
16 }
17
18 void test_conversion(void) {
19 X *_Nullable_result nr;
20 X *_Nonnull l = nr; // expected-warning{{implicit conversion from nullable pointer 'X * _Nullable_result' to non-nullable pointer type 'X * _Nonnull'}}
21
22 (void)^(X * _Nullable_result p) {
23 X *_Nonnull l = p; // expected-warning{{implicit conversion from nullable pointer 'X * _Nullable_result' to non-nullable pointer type 'X * _Nonnull'}}
24 };
25 }
26
27 void test_dup(void) {
28 id _Nullable_result _Nullable_result a; // expected-warning {{duplicate nullability specifier '_Nullable_result'}}
29 id _Nullable _Nullable_result b; // expected-error{{nullability specifier '_Nullable_result' conflicts with existing specifier '_Nullable'}}
30 id _Nullable_result _Nonnull c; // expected-error{{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable_result'}}
31 }
32
33 @interface NoContextSensitive
34 -(nullable_result id)m; // expected-error {{expected a type}}
35 @property(assign, nullable_result) id p; // expected-error{{unknown property attribute 'nullable_result'}}
36 @end