150
|
1 // RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class %s
|
|
2 // RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class -DNOWARN %s
|
|
3
|
|
4 @interface NSString
|
|
5
|
|
6 + (NSString*
|
|
7 #ifndef NOWARN
|
|
8 _Nullable
|
|
9 #else
|
|
10 _Nonnull
|
|
11 #endif
|
|
12 ) stringWithUTF8String:(const char*)x;
|
|
13
|
|
14 @end
|
|
15
|
|
16 void takesNonNull(NSString * _Nonnull ptr);
|
|
17
|
|
18 void testBoxedString() {
|
|
19 // No diagnostic emitted as this doesn't need a stringWithUTF8String message
|
|
20 // send.
|
|
21 takesNonNull(@("hey"));
|
|
22 takesNonNull(@(u8"hey"));
|
|
23
|
|
24 // If the string isn't a valid UTF-8 string, a diagnostic is emitted since the
|
|
25 // boxed expression turns into a message send.
|
|
26 takesNonNull(@(u8"\xFF")); // expected-warning {{string is ill-formed as UTF-8}}
|
|
27 takesNonNull(@(u8"\xC0\x80")); // expected-warning {{string is ill-formed as UTF-8}}
|
|
28
|
|
29 const char *str = "hey";
|
|
30 takesNonNull([NSString stringWithUTF8String:str]);
|
|
31 takesNonNull(@(str));
|
|
32 #ifndef NOWARN
|
|
33 // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
|
|
34 // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
|
|
35 // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
|
|
36 // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}}
|
|
37 #endif
|
|
38 }
|