annotate clang/test/SemaObjC/transfer-boxed-string-nullability.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class -DNOWARN %s
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 @interface NSString
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 + (NSString*
anatofuz
parents:
diff changeset
7 #ifndef NOWARN
anatofuz
parents:
diff changeset
8 _Nullable
anatofuz
parents:
diff changeset
9 #else
anatofuz
parents:
diff changeset
10 _Nonnull
anatofuz
parents:
diff changeset
11 #endif
anatofuz
parents:
diff changeset
12 ) stringWithUTF8String:(const char*)x;
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 @end
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 void takesNonNull(NSString * _Nonnull ptr);
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 void testBoxedString() {
anatofuz
parents:
diff changeset
19 // No diagnostic emitted as this doesn't need a stringWithUTF8String message
anatofuz
parents:
diff changeset
20 // send.
anatofuz
parents:
diff changeset
21 takesNonNull(@("hey"));
anatofuz
parents:
diff changeset
22 takesNonNull(@(u8"hey"));
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 // If the string isn't a valid UTF-8 string, a diagnostic is emitted since the
anatofuz
parents:
diff changeset
25 // boxed expression turns into a message send.
anatofuz
parents:
diff changeset
26 takesNonNull(@(u8"\xFF")); // expected-warning {{string is ill-formed as UTF-8}}
anatofuz
parents:
diff changeset
27 takesNonNull(@(u8"\xC0\x80")); // expected-warning {{string is ill-formed as UTF-8}}
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 const char *str = "hey";
anatofuz
parents:
diff changeset
30 takesNonNull([NSString stringWithUTF8String:str]);
anatofuz
parents:
diff changeset
31 takesNonNull(@(str));
anatofuz
parents:
diff changeset
32 #ifndef NOWARN
anatofuz
parents:
diff changeset
33 // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
anatofuz
parents:
diff changeset
34 // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
anatofuz
parents:
diff changeset
35 // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
anatofuz
parents:
diff changeset
36 // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
anatofuz
parents:
diff changeset
37 #endif
anatofuz
parents:
diff changeset
38 }