summaryrefslogtreecommitdiffstats
path: root/clang/test/FixIt/fixit-nullability-declspec.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2015-06-19 17:51:05 +0000
committerDouglas Gregor <dgregor@apple.com>2015-06-19 17:51:05 +0000
commit261a89b0f70b3193b5358698eb92d18c4c855b36 (patch)
tree9c12c7684ec69fc50b2e33f16c10314ffa033017 /clang/test/FixIt/fixit-nullability-declspec.cpp
parent4f093bf1ce0c6b4c9cd4472fbaa0b2b0a942a38c (diff)
downloadbcm5719-llvm-261a89b0f70b3193b5358698eb92d18c4c855b36.tar.gz
bcm5719-llvm-261a89b0f70b3193b5358698eb92d18c4c855b36.zip
Introduce type nullability specifiers for C/C++.
Introduces the type specifiers __nonnull, __nullable, and __null_unspecified that describe the nullability of the pointer type to which the specifier appertains. Nullability type specifiers improve on the existing nonnull attributes in a few ways: - They apply to types, so one can represent a pointer to a non-null pointer, use them in function pointer types, etc. - As type specifiers, they are syntactically more lightweight than __attribute__s or [[attribute]]s. - They can express both the notion of 'should never be null' and also 'it makes sense for this to be null', and therefore can more easily catch errors of omission where one forgot to annotate the nullability of a particular pointer (this will come in a subsequent patch). Nullability type specifiers are maintained as type sugar, and therefore have no effect on mangling, encoding, overloading, etc. Nonetheless, they will be used for warnings about, e.g., passing 'null' to a method that does not accept it. This is the C/C++ part of rdar://problem/18868820. llvm-svn: 240146
Diffstat (limited to 'clang/test/FixIt/fixit-nullability-declspec.cpp')
-rw-r--r--clang/test/FixIt/fixit-nullability-declspec.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/test/FixIt/fixit-nullability-declspec.cpp b/clang/test/FixIt/fixit-nullability-declspec.cpp
new file mode 100644
index 00000000000..2ac20b9d9b4
--- /dev/null
+++ b/clang/test/FixIt/fixit-nullability-declspec.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fblocks -Werror=nullability-declspec -x c++ -verify %s
+
+// RUN: cp %s %t
+// RUN: not %clang_cc1 -fixit -fblocks -Werror=nullability-declspec -x c++ %t
+// RUN: %clang_cc1 -fblocks -Werror=nullability-declspec -x c++ %t
+
+__nullable int *ip1; // expected-error{{nullability specifier '__nullable' cannot be applied to non-pointer type 'int'; did you mean to apply the specifier to the pointer?}}
+__nullable int (*fp1)(int); // expected-error{{nullability specifier '__nullable' cannot be applied to non-pointer type 'int'; did you mean to apply the specifier to the function pointer?}}
+__nonnull int (^bp1)(int); // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'int'; did you mean to apply the specifier to the block pointer?}}
OpenPOWER on IntegriCloud