summaryrefslogtreecommitdiff
path: root/test/SemaObjC/nonnull.m
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaObjC/nonnull.m')
-rw-r--r--test/SemaObjC/nonnull.m28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/SemaObjC/nonnull.m b/test/SemaObjC/nonnull.m
index 902105b924dd..a345eddbf1e4 100644
--- a/test/SemaObjC/nonnull.m
+++ b/test/SemaObjC/nonnull.m
@@ -74,6 +74,9 @@ void func6(dispatch_object_t _head) {
@interface NSObject
- (void)doSomethingWithNonNullPointer:(void *)ptr :(int)iarg : (void*)ptr1 __attribute__((nonnull(1, 3)));
+ (void)doSomethingClassyWithNonNullPointer:(void *)ptr __attribute__((nonnull(1)));
+- (void*)returnsCNonNull __attribute__((returns_nonnull)); // no-warning
+- (id)returnsObjCNonNull __attribute__((returns_nonnull)); // no-warning
+- (int)returnsIntNonNull __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}}
@end
extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
@@ -82,6 +85,7 @@ extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
{
void * vp;
}
+- (void*) testRetNull __attribute__((returns_nonnull));
@end
@implementation IMP
@@ -93,5 +97,29 @@ extern void DoSomethingNotNull(void *db) __attribute__((nonnull(1)));
DoSomethingNotNull(NULL); // expected-warning {{null passed to a callee which requires a non-null argument}}
[object doSomethingWithNonNullPointer:vp:1:vp];
}
+- (void*) testRetNull {
+ return 0; // expected-warning {{null returned from method that requires a non-null return value}}
+}
+@end
+
+__attribute__((objc_root_class))
+@interface TestNonNullParameters
+- (void) doNotPassNullParameterNonPointerArg:(int)__attribute__((nonnull))x; // expected-warning {{'nonnull' attribute only applies to pointer arguments}}
+- (void) doNotPassNullParameter:(id)__attribute__((nonnull))x;
+- (void) doNotPassNullParameterArgIndex:(id)__attribute__((nonnull(1)))x; // expected-warning {{'nonnull' attribute when used on parameters takes no arguments}}
+- (void) doNotPassNullOnMethod:(id)x __attribute__((nonnull(1)));
@end
+void test(TestNonNullParameters *f) {
+ [f doNotPassNullParameter:0]; // expected-warning {{null passed to a callee which requires a non-null argument}}
+ [f doNotPassNullParameterArgIndex:0]; // no-warning
+ [f doNotPassNullOnMethod:0]; // expected-warning {{null passed to a callee which requires a non-null argument}}
+}
+
+
+void PR18795(int (^g)(const char *h, ...) __attribute__((nonnull(1))) __attribute__((nonnull))) {
+ g(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}
+void PR18795_helper() {
+ PR18795(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}