brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 71ee2f4 Raw
39 lines · plain
1// RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class %s2// RUN: %clang_cc1 -fblocks -fobjc-arc -Wnullable-to-nonnull-conversion -fsyntax-only -verify -Wno-objc-root-class -DNOWARN %s3 4@interface NSString5 6+ (NSString*7#ifndef NOWARN8  _Nullable9#else10  _Nonnull11#endif12) stringWithUTF8String:(const char*)x;13 14@end15 16void takesNonNull(NSString * _Nonnull ptr);17 18void testBoxedString(void) {19  // No diagnostic emitted as this doesn't need a stringWithUTF8String message20  // 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 the25  // 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 NOWARN33  // 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#endif38}39