summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/non-null-warning.c
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/Sema/non-null-warning.c
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/Sema/non-null-warning.c')
-rw-r--r--clang/test/Sema/non-null-warning.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/test/Sema/non-null-warning.c b/clang/test/Sema/non-null-warning.c
new file mode 100644
index 00000000000..0cabc713baf
--- /dev/null
+++ b/clang/test/Sema/non-null-warning.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -Wnonnull -Wnullability %s -verify
+// rdar://19160762
+
+#if __has_feature(nullability)
+#else
+# error nullability feature should be defined
+#endif
+
+
+int * __nullable foo(int * __nonnull x);
+
+int *__nonnull ret_nonnull();
+
+int *foo(int *x) {
+ return 0;
+}
+
+int * __nullable foo1(int * __nonnull x); // expected-note {{previous declaration is here}}
+
+int *foo1(int * __nullable x) { // expected-warning {{nullability specifier '__nullable' conflicts with existing specifier '__nonnull'}}
+ return 0;
+}
+
+int * __nullable foo2(int * __nonnull x);
+
+int *foo2(int * __nonnull x) {
+ return 0;
+}
+
+int * __nullable foo3(int * __nullable x); // expected-note {{previous declaration is here}}
+
+int *foo3(int * __nonnull x) { // expected-warning {{nullability specifier '__nonnull' conflicts with existing specifier '__nullable'}}
+ return 0;
+}
+
OpenPOWER on IntegriCloud