summaryrefslogtreecommitdiffstats
path: root/clang/test/Parser/nullability.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/Parser/nullability.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/Parser/nullability.c')
-rw-r--r--clang/test/Parser/nullability.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/test/Parser/nullability.c b/clang/test/Parser/nullability.c
new file mode 100644
index 00000000000..f2b6abf73dc
--- /dev/null
+++ b/clang/test/Parser/nullability.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -Wno-nullability-declspec -pedantic %s -verify
+
+__nonnull int *ptr; // expected-warning{{type nullability specifier '__nonnull' is a Clang extension}}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnullability-extension"
+__nonnull int *ptr2; // no-warning
+#pragma clang diagnostic pop
+
+#if __has_feature(nullability)
+# error Nullability should not be supported in C under -pedantic -std=c99
+#endif
+
+#if !__has_extension(nullability)
+# error Nullability should always be supported as an extension
+#endif
OpenPOWER on IntegriCloud