diff options
Diffstat (limited to 'test/SemaObjC')
21 files changed, 320 insertions, 54 deletions
diff --git a/test/SemaObjC/arc-decls.m b/test/SemaObjC/arc-decls.m index c728f00c7e..0abd45dac3 100644 --- a/test/SemaObjC/arc-decls.m +++ b/test/SemaObjC/arc-decls.m @@ -3,13 +3,29 @@ // rdar://8843524 struct A { - id x; + id x[4]; + id y; }; union u { id u; // expected-error {{ARC forbids Objective-C objects in union}} }; +union u_nontrivial_c { + struct A a; // expected-error {{non-trivial C types are disallowed in union}} +}; + +// Volatile fields are fine. +struct C { + volatile int x[4]; + volatile int y; +}; + +union u_trivial_c { + volatile int b; + struct C c; +}; + @interface I { struct A a; struct B { diff --git a/test/SemaObjC/arc-property-decl-attrs.m b/test/SemaObjC/arc-property-decl-attrs.m index 6638054bef..833998d425 100644 --- a/test/SemaObjC/arc-property-decl-attrs.m +++ b/test/SemaObjC/arc-property-decl-attrs.m @@ -287,3 +287,7 @@ __attribute__((objc_root_class)) @synthesize collision = _collision; // expected-note {{property synthesized here}} @end + +// This used to crash because we'd temporarly store the weak attribute on the +// declaration specifier, then deallocate it when clearing the declarator. +id i1, __weak i2, i3; diff --git a/test/SemaObjC/arc-repeated-weak.mm b/test/SemaObjC/arc-repeated-weak.mm index 6c7a6292f9..4eec4d2fe6 100644 --- a/test/SemaObjC/arc-repeated-weak.mm +++ b/test/SemaObjC/arc-repeated-weak.mm @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -std=c++14 -Warc-repeated-use-of-weak -verify %s -// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++14 -Warc-repeated-use-of-weak -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s +// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-weak -fblocks -Wno-objc-root-class -std=c++11 -Warc-repeated-use-of-weak -verify %s @interface Test { @public @@ -467,18 +467,6 @@ void foo() { __typeof__(NSBundle2.foo2.weakProp) t5; } -void testAuto() { - auto __weak wp = NSBundle2.foo2.weakProp; -} - -void testLambdaCaptureInit() { - [capture(NSBundle2.foo2.weakProp)] {} (); -} - -void testAutoNew() { - auto p = new auto(NSBundle2.foo2.weakProp); -} - // This used to crash in the constructor of WeakObjectProfileTy when a // DeclRefExpr was passed that didn't reference a VarDecl. diff --git a/test/SemaObjC/attr-availability-priority.m b/test/SemaObjC/attr-availability-priority.m new file mode 100644 index 0000000000..83a1668d2b --- /dev/null +++ b/test/SemaObjC/attr-availability-priority.m @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -triple arm64-apple-tvos12.0 -fsyntax-only -verify %s + +void explicit() __attribute__((availability(tvos, introduced=11.0, deprecated=12.0))); // expected-note {{marked deprecated here}} +void inferred() __attribute__((availability(ios, introduced=11.0, deprecated=12.0))); // expected-note {{marked deprecated here}} +void explicitOverInferred() +__attribute__((availability(ios, introduced=11.0, deprecated=12.0))) +__attribute__((availability(tvos, introduced=11.0))); +void explicitOverInferred2() +__attribute__((availability(tvos, introduced=11.0))) +__attribute__((availability(ios, introduced=11.0, deprecated=12.0))); + +void simpleUsage() { + explicit(); // expected-warning{{'explicit' is deprecated: first deprecated in tvOS 12.0}} + inferred(); // expected-warning{{'inferred' is deprecated: first deprecated in tvOS 12.0}} + // ok, not deprecated for tvOS. + explicitOverInferred(); + explicitOverInferred2(); +} + +#pragma clang attribute push (__attribute__((availability(tvos, introduced=11.0, deprecated=12.0))), apply_to=function) + +void explicitFromPragma(); // expected-note {{marked deprecated here}} +void explicitWinsOverExplicitFromPragma() __attribute__((availability(tvos, introduced=11.0))); +void implicitLosesOverExplicitFromPragma() __attribute__((availability(ios, introduced=11.0))); // expected-note {{marked deprecated here}} + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((availability(ios, introduced=11.0, deprecated=12.0))), apply_to=function) + +void implicitFromPragma(); // expected-note {{marked deprecated here}} +void explicitWinsOverImplicitFromPragma() __attribute__((availability(tvos, introduced=11.0))); +void implicitWinsOverImplicitFromPragma() __attribute__((availability(ios, introduced=11.0))); + +#pragma clang attribute pop + +#pragma clang attribute push (__attribute__((availability(tvos, introduced=11.0, deprecated=12.0))), apply_to=function) +#pragma clang attribute push (__attribute__((availability(ios, introduced=11.0, deprecated=11.3))), apply_to=function) + +void pragmaExplicitWinsOverPragmaImplicit(); // expected-note {{marked deprecated here}} + +#pragma clang attribute pop +#pragma clang attribute pop + +void pragmaUsage() { + explicitFromPragma(); // expected-warning {{'explicitFromPragma' is deprecated: first deprecated in tvOS 12.0}} + explicitWinsOverExplicitFromPragma(); // ok + implicitLosesOverExplicitFromPragma(); // expected-warning {{'implicitLosesOverExplicitFromPragma' is deprecated: first deprecated in tvOS 12.0}} + + implicitFromPragma(); // expected-warning {{'implicitFromPragma' is deprecated: first deprecated in tvOS 12.0}} + explicitWinsOverImplicitFromPragma(); // ok + implicitWinsOverImplicitFromPragma(); // ok + pragmaExplicitWinsOverPragmaImplicit(); // expected-warning {{'pragmaExplicitWinsOverPragmaImplicit' is deprecated: first deprecated in tvOS 12.0}} +} diff --git a/test/SemaObjC/attr-designated-init.m b/test/SemaObjC/attr-designated-init.m index 0508588478..7d1e7008e8 100644 --- a/test/SemaObjC/attr-designated-init.m +++ b/test/SemaObjC/attr-designated-init.m @@ -3,7 +3,7 @@ #define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer)) #define NS_UNAVAILABLE __attribute__((unavailable)) -void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}} +void fnfoo(void) NS_DESIGNATED_INITIALIZER; // expected-error {{'objc_designated_initializer' attribute only applies to Objective-C methods}} @protocol P1 -(id)init NS_DESIGNATED_INITIALIZER; // expected-error {{only applies to init methods of interface or class extension declarations}} @@ -389,6 +389,19 @@ __attribute__((objc_root_class)) } @end +@interface SubTest1Ext : Test1 +-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER; +@end +// Mark 'init' as unavailable in the extension to silence warning. +@interface SubTest1Ext() +-(instancetype)init NS_UNAVAILABLE; +@end +@implementation SubTest1Ext +-(instancetype)initWithRequiredParameter:(id)foo { + return [super init]; +} +@end + @interface Test2 : NSObject @end @interface SubTest2 : Test2 @@ -428,3 +441,16 @@ __attribute__((objc_root_class)) @interface CategoryForMissingInterface(Cat) // expected-error{{cannot find interface declaration}} - (instancetype)init NS_DESIGNATED_INITIALIZER; // expected-error{{only applies to init methods of interface or class extension declarations}} @end + +@interface TwoAttrs +-(instancetype)foo + __attribute__((objc_designated_initializer)) + __attribute__((objc_method_family(init))); +-(instancetype)bar + __attribute__((objc_method_family(init))) + __attribute__((objc_designated_initializer)); +-(instancetype)baz + __attribute__((objc_designated_initializer, objc_method_family(init))); +-(instancetype)quux + __attribute__((objc_method_family(init), objc_designated_initializer)); +@end diff --git a/test/SemaObjC/attr-objc-non-lazy.m b/test/SemaObjC/attr-objc-non-lazy.m new file mode 100644 index 0000000000..bbbbd74145 --- /dev/null +++ b/test/SemaObjC/attr-objc-non-lazy.m @@ -0,0 +1,39 @@ +// RUN: %clang_cc1 -verify -Wno-objc-root-class -fsyntax-only %s + +__attribute__((objc_nonlazy_class)) +@interface A +@end +@implementation A +@end + +__attribute__((objc_nonlazy_class)) int X; // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} + +__attribute__((objc_nonlazy_class())) +@interface B +@end +@implementation B +@end + +__attribute__((objc_nonlazy_class("foo"))) // expected-error{{'objc_nonlazy_class' attribute takes no arguments}} +@interface C +@end +@implementation C +@end + +__attribute__((objc_nonlazy_class)) // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} +@protocol B +@end + +__attribute__((objc_nonlazy_class)) // expected-error {{'objc_nonlazy_class' attribute only applies to Objective-C interfaces}} +void foo(); + +@interface E +@end + +__attribute__((objc_nonlazy_class)) +@implementation E +@end + +__attribute__((objc_nonlazy_class)) +@implementation E (MyCat) +@end diff --git a/test/SemaObjC/boxing-illegal.m b/test/SemaObjC/boxing-illegal.m index 59b5c8b710..4493819288 100644 --- a/test/SemaObjC/boxing-illegal.m +++ b/test/SemaObjC/boxing-illegal.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wattributes -fpascal-strings %s typedef long NSInteger; typedef unsigned long NSUInteger; @@ -57,6 +57,19 @@ void testEnum(void *p) { box = @(*(enum ForwE*)p); // expected-error {{incomplete type 'enum ForwE' used in a boxed expression}} } +@interface NSString +@end + +void testStringLiteral() { + NSString *s; + s = @("abc"); + s = @(u8"abc"); + s = @(u"abc"); // expected-error {{illegal type 'unsigned short *' used in a boxed expression}} + s = @(U"abc"); // expected-error {{illegal type 'unsigned int *' used in a boxed expression}} + s = @(L"abc"); // expected-error-re {{illegal type {{.*}} used in a boxed expression}} + s = @("\pabc"); // expected-error {{illegal type 'unsigned char *' used in a boxed expression}} +} + // rdar://13333205 @class NSMutableDictionary; diff --git a/test/SemaObjC/call-unavailable-init-in-self.m b/test/SemaObjC/call-unavailable-init-in-self.m index fa6f670cc9..48fc2326af 100644 --- a/test/SemaObjC/call-unavailable-init-in-self.m +++ b/test/SemaObjC/call-unavailable-init-in-self.m @@ -5,13 +5,24 @@ + (instancetype)new; + (instancetype)alloc; +- (void)declaredInSuper; + +@end + +@interface NSObject (Category) + +- (void)declaredInSuperCategory; + @end @interface Sub: NSObject - (instancetype)init __attribute__((unavailable)); // expected-note 4 {{'init' has been explicitly marked unavailable here}} -- (void)notImplemented __attribute__((unavailable)); // expected-note {{'notImplemented' has been explicitly marked unavailable here}} +- (void)notImplemented __attribute__((unavailable)); + +- (void)declaredInSuper __attribute__((unavailable)); +- (void)declaredInSuperCategory __attribute__((unavailable)); @end @@ -34,7 +45,14 @@ } - (void)reportUseOfUnimplemented { - [self notImplemented]; // expected-error {{'notImplemented' is unavailable}} + [self notImplemented]; +} + +- (void)allowSuperCallUsingSelf { + [self declaredInSuper]; + [[Sub alloc] declaredInSuper]; + [self declaredInSuperCategory]; + [[Sub alloc] declaredInSuperCategory]; } @end diff --git a/test/SemaObjC/conversion.m b/test/SemaObjC/conversion.m index 88a1a44b21..743f7440e2 100644 --- a/test/SemaObjC/conversion.m +++ b/test/SemaObjC/conversion.m @@ -14,4 +14,11 @@ void radar14415662(RDar14415662 *f, char x, int y) { x = y; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}} } +__attribute__((objc_root_class)) @interface DoubleProp +@property double d; +@end +void use_double_prop(DoubleProp *dp) { + double local = 42; + dp.d += local; // no warning +} diff --git a/test/SemaObjC/enum-fixed-type.m b/test/SemaObjC/enum-fixed-type.m index 88c895a339..b4135a555a 100644 --- a/test/SemaObjC/enum-fixed-type.m +++ b/test/SemaObjC/enum-fixed-type.m @@ -1,9 +1,11 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -xc %s +#ifdef __OBJC__ #if !__has_feature(objc_fixed_enum) # error Enumerations with a fixed underlying type are not supported #endif +#endif #if !__has_extension(cxx_fixed_enum) # error Enumerations with a fixed underlying type are not supported diff --git a/test/SemaObjC/infer-availability-from-init.m b/test/SemaObjC/infer-availability-from-init.m index f9996ec708..6719400a9f 100644 --- a/test/SemaObjC/infer-availability-from-init.m +++ b/test/SemaObjC/infer-availability-from-init.m @@ -47,12 +47,25 @@ void usenotmyobject() { } @interface FromSelf : NSObject --(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}} +-(instancetype)init __attribute__((unavailable)); +(FromSelf*)another_one; @end @implementation FromSelf +(FromSelf*)another_one { - [self new]; // expected-error{{'new' is unavailable}} + [self new]; +} +@end + +@interface NoInit : NSObject +-(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}} +@end + +@interface NoInitSub : NoInit @end + +@implementation NoInitSub +-(void)meth:(Class)c { + [c new]; // No error; unknown interface. + [NoInitSub new]; // expected-error {{'new' is unavailable}} } @end diff --git a/test/SemaObjC/kindof.m b/test/SemaObjC/kindof.m index 9d758d3cfb..b2c3205182 100644 --- a/test/SemaObjC/kindof.m +++ b/test/SemaObjC/kindof.m @@ -384,9 +384,17 @@ void testNullability() { } @end +// --------------------------------------------------------------------------- +// __kindof on type parameters +// --------------------------------------------------------------------------- + @interface NSGeneric<ObjectType> : NSObject - (void)test:(__kindof ObjectType)T; // expected-note{{passing argument to parameter 'T' here}} - (void)mapUsingBlock:(id (^)(__kindof ObjectType))block; +@property (copy) ObjectType object; +@property (copy) __kindof ObjectType kindof_object; + +@property (copy) __kindof ObjectType _Nonnull nonnull_kindof_object; @end @implementation NSGeneric - (void)test:(id)T { @@ -395,6 +403,11 @@ void testNullability() { } @end +@interface NSDefaultGeneric<ObjectType : NSString *> : NSObject +@property (copy) ObjectType object; +@property (copy) __kindof ObjectType kindof_object; +@end + void testGeneric(NSGeneric<NSString*> *generic) { NSObject *NSObject_obj; // Assign from NSObject_obj to __kindof NSString*. @@ -403,6 +416,45 @@ void testGeneric(NSGeneric<NSString*> *generic) { [generic test:NSString_str]; } +void testGenericAssignment() { + NSMutableString *NSMutableString_str; + NSNumber *NSNumber_obj; + + NSGeneric<NSString*> *generic; + NSMutableString_str = generic.object; // expected-warning{{incompatible pointer types}} + NSNumber_obj = generic.object; // expected-warning{{incompatible pointer types}} + NSMutableString_str = generic.kindof_object; + NSNumber_obj = generic.kindof_object; // expected-warning{{incompatible pointer types assigning to 'NSNumber *' from '__kindof NSString *'}} + + NSGeneric<__kindof NSString*> *kindof_generic; + NSMutableString_str = kindof_generic.object; + NSNumber_obj = kindof_generic.object; // expected-warning{{incompatible pointer types assigning to 'NSNumber *' from '__kindof NSString *'}} + NSMutableString_str = kindof_generic.kindof_object; + NSNumber_obj = kindof_generic.kindof_object; // expected-warning{{incompatible pointer types assigning to 'NSNumber *' from '__kindof __kindof NSString *'}} + + NSDefaultGeneric *default_generic; + NSMutableString_str = default_generic.object; + NSNumber_obj = default_generic.object; // expected-warning{{incompatible pointer types}} + NSMutableString_str = default_generic.kindof_object; + NSNumber_obj = default_generic.kindof_object; // expected-warning{{incompatible pointer types assigning to 'NSNumber *' from '__kindof __kindof NSString *'}} + + typedef NSString *Typedef_NSString; + NSGeneric<Typedef_NSString> *typedef_generic; + NSMutableString_str = typedef_generic.object; // expected-warning{{incompatible pointer types}} + NSNumber_obj = typedef_generic.object; // expected-warning{{incompatible pointer types}} + NSMutableString_str = typedef_generic.kindof_object; + NSNumber_obj = typedef_generic.kindof_object; // expected-warning{{incompatible pointer types assigning to 'NSNumber *' from '__kindof Typedef_NSString'}} +} + +void testKindofNonObjectType() { + typedef void (^BlockType)(int); + NSGeneric<BlockType> *generic; +} + +void testKindofNullability(NSGeneric<NSString*> *generic) { + generic.nonnull_kindof_object = 0; // expected-warning{{null passed to a callee that requires a non-null argument}} +} + // Check that clang doesn't crash when a type parameter is illegal. @interface Array1<T> : NSObject @end diff --git a/test/SemaObjC/method-unused-attribute.m b/test/SemaObjC/method-unused-attribute.m index d604c3975c..d8e9659b51 100644 --- a/test/SemaObjC/method-unused-attribute.m +++ b/test/SemaObjC/method-unused-attribute.m @@ -1,5 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -Wunused-parameter -verify -Wno-objc-root-class %s +// -Wunused-parameter ignores ObjC method parameters that are unused. + +// expected-no-diagnostics + @interface INTF - (void) correct_use_of_unused: (void *) notice : (id)another_arg; - (void) will_warn_unused_arg: (void *) notice : (id)warn_unused; @@ -9,7 +13,7 @@ @implementation INTF - (void) correct_use_of_unused: (void *) __attribute__((unused)) notice : (id) __attribute__((unused)) newarg{ } -- (void) will_warn_unused_arg: (void *) __attribute__((unused)) notice : (id)warn_unused {} // expected-warning {{unused parameter 'warn_unused'}} -- (void) unused_attr_on_decl_ignored: (void *) will_warn{} // expected-warning {{unused parameter 'will_warn'}} +- (void) will_warn_unused_arg: (void *) __attribute__((unused)) notice : (id)warn_unused {} +- (void) unused_attr_on_decl_ignored: (void *) will_warn{} @end diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m index e1f31937a5..4859432719 100644 --- a/test/SemaObjC/nonnull.m +++ b/test/SemaObjC/nonnull.m @@ -125,3 +125,9 @@ void PR18795_helper() { } void (^PR23117)(int *) = ^(int *p1) __attribute__((nonnull(1))) {}; + +typedef int *intptr; +#pragma clang assume_nonnull begin +intptr a, b; +intptr c, (*d)(); +#pragma clang assume_nonnull end diff --git a/test/SemaObjC/objc-asm-attribute-neg-test.m b/test/SemaObjC/objc-asm-attribute-neg-test.m index 98f39fb900..9941189357 100644 --- a/test/SemaObjC/objc-asm-attribute-neg-test.m +++ b/test/SemaObjC/objc-asm-attribute-neg-test.m @@ -19,7 +19,7 @@ __attribute__((objc_runtime_name("MySecretNamespace.Message"))) // expected-erro id MyIVAR; } __attribute__((objc_runtime_name("MySecretNamespace.Message"))) -@property int MyProperty; // expected-error {{prefix attribute must be followed by an interface or protocol}}}} +@property int MyProperty; // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}}}} - (int) getMyProperty __attribute__((objc_runtime_name("MySecretNamespace.Message"))); // expected-error {{'objc_runtime_name' attribute only applies to}} @@ -28,15 +28,23 @@ __attribute__((objc_runtime_name("MySecretNamespace.Message"))) @end __attribute__((objc_runtime_name("MySecretNamespace.ForwardClass"))) -@class ForwardClass; // expected-error {{prefix attribute must be followed by an interface or protocol}} +@class ForwardClass; // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}} __attribute__((objc_runtime_name("MySecretNamespace.ForwardProtocol"))) @protocol ForwardProtocol; -__attribute__((objc_runtime_name("MySecretNamespace.Message"))) -@implementation Message // expected-error {{prefix attribute must be followed by an interface or protocol}} -__attribute__((objc_runtime_name("MySecretNamespace.Message"))) -- (id) MyMethod { +@implementation Message +// expected-error@+1 {{'objc_runtime_name' attribute only applies to Objective-C interfaces and Objective-C protocols}} +- (id) MyMethod __attribute__((objc_runtime_name("MySecretNamespace.Message"))) { return MyIVAR; } + +-(int)getMyProperty { return 0; } +-(void)setMyProperty:(int)arg {} @end + +@interface NoImpl @end + +// expected-error@+1 {{'objc_runtime_name' attribute only applies to Objective-C interfaces and Objective-C protocols}} +__attribute__((objc_runtime_name("MySecretNamespace.Message"))) +@implementation NoImpl @end diff --git a/test/SemaObjC/objc-literal-sig.m b/test/SemaObjC/objc-literal-sig.m index 86f42d3abc..48f69165ef 100644 --- a/test/SemaObjC/objc-literal-sig.m +++ b/test/SemaObjC/objc-literal-sig.m @@ -39,6 +39,8 @@ typedef _Bool BOOL; // All tests are doubled to make sure that a bad method is not saved // and then used un-checked. +const char *getStr(void); + void test_sig() { (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}} (void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}} @@ -46,6 +48,6 @@ void test_sig() { id array2 = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}} id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}} id dict2 = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}} - id str = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}} - id str2 = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}} + id str = @(getStr()); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}} + id str2 = @(getStr()); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}} } diff --git a/test/SemaObjC/parameterized_classes_subst.m b/test/SemaObjC/parameterized_classes_subst.m index da2d56f11b..d14a6e9deb 100644 --- a/test/SemaObjC/parameterized_classes_subst.m +++ b/test/SemaObjC/parameterized_classes_subst.m @@ -104,6 +104,12 @@ __attribute__((objc_root_class)) @property (nonatomic,retain) ViewType view; @end +@interface TypedefTypeParam<T> : NSObject +typedef T AliasT; +- (void)test:(AliasT)object; +// expected-note@-1 {{parameter 'object' here}} +@end + // -------------------------------------------------------------------------- // Nullability // -------------------------------------------------------------------------- @@ -190,6 +196,7 @@ void test_message_send_param( MutableSetOfArrays<NSString *> *mutStringArraySet, NSMutableSet *mutSet, MutableSetOfArrays *mutArraySet, + TypedefTypeParam<NSString *> *typedefTypeParam, void (^block)(void)) { Window *window; @@ -199,6 +206,7 @@ void test_message_send_param( [mutStringArraySet addObject: window]; // expected-warning{{parameter of type 'NSArray<NSString *> *'}} [mutSet addObject: window]; // expected-warning{{parameter of incompatible type 'id<NSCopying>'}} [mutArraySet addObject: window]; // expected-warning{{parameter of incompatible type 'id<NSCopying>'}} + [typedefTypeParam test: window]; // expected-warning{{parameter of type 'NSString *'}} [block addObject: window]; // expected-warning{{parameter of incompatible type 'id<NSCopying>'}} } diff --git a/test/SemaObjC/transfer-boxed-string-nullability.m b/test/SemaObjC/transfer-boxed-string-nullability.m index 42604ef4a6..a3b6832be4 100644 --- a/test/SemaObjC/transfer-boxed-string-nullability.m +++ b/test/SemaObjC/transfer-boxed-string-nullability.m @@ -16,13 +16,23 @@ void takesNonNull(NSString * _Nonnull ptr); void testBoxedString() { + // No diagnostic emitted as this doesn't need a stringWithUTF8String message + // send. + takesNonNull(@("hey")); + takesNonNull(@(u8"hey")); + + // If the string isn't a valid UTF-8 string, a diagnostic is emitted since the + // boxed expression turns into a message send. + takesNonNull(@(u8"\xFF")); // expected-warning {{string is ill-formed as UTF-8}} + takesNonNull(@(u8"\xC0\x80")); // expected-warning {{string is ill-formed as UTF-8}} + const char *str = "hey"; takesNonNull([NSString stringWithUTF8String:str]); takesNonNull(@(str)); #ifndef NOWARN - // expected-warning@-3 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} - // expected-warning@-3 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} -#else - // expected-no-diagnostics + // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} + // expected-warning@-7 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} + // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} + // expected-warning@-5 {{implicit conversion from nullable pointer 'NSString * _Nullable' to non-nullable pointer type 'NSString * _Nonnull'}} #endif } diff --git a/test/SemaObjC/typo-correction-subscript.m b/test/SemaObjC/typo-correction-subscript.m new file mode 100644 index 0000000000..19eb860f2b --- /dev/null +++ b/test/SemaObjC/typo-correction-subscript.m @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -triple i386-apple-macosx10.10 -fobjc-arc -fsyntax-only -Wno-objc-root-class %s -verify -disable-free + +@class Dictionary; + +@interface Test +@end +@implementation Test +// rdar://problem/47403222 +- (void)rdar47403222:(Dictionary *)opts { + [self undeclaredMethod:undeclaredArg]; + // expected-error@-1{{no visible @interface for 'Test' declares the selector 'undeclaredMethod:'}} + opts[(__bridge id)undeclaredKey] = 0; + // expected-error@-1{{use of undeclared identifier 'undeclaredKey'}} +} +@end diff --git a/test/SemaObjC/unused.m b/test/SemaObjC/unused.m index f31e4709f5..088f5b4577 100644 --- a/test/SemaObjC/unused.m +++ b/test/SemaObjC/unused.m @@ -33,7 +33,7 @@ void test2() { // expected-note {{introduce a parameter name to make 'x' part of the selector}} \ // expected-note {{or insert whitespace before ':' to use 'x' as parameter name and have an empty entry in the selector}} -(int)y: // expected-warning {{unused}} expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \ +(int)y: // expected-warning {{'y' used as the name of the previous parameter rather than as part of the selector}} \ // expected-note {{introduce a parameter name to make 'y' part of the selector}} \ // expected-note {{or insert whitespace before ':' to use 'y' as parameter name and have an empty entry in the selector}} (int) __attribute__((unused))z { return x; } diff --git a/test/SemaObjC/warn-implicit-self-in-block.m b/test/SemaObjC/warn-implicit-self-in-block.m deleted file mode 100644 index a7ee16ec70..0000000000 --- a/test/SemaObjC/warn-implicit-self-in-block.m +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -Wimplicit-retain-self -verify %s -// rdar://11194874 - -@interface Root @end - -@interface I : Root -{ - int _bar; -} -@end - -@implementation I - - (void)foo{ - ^{ - _bar = 3; // expected-warning {{block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior}} - }(); - } -@end |