diff options
author | Douglas Gregor <dgregor@apple.com> | 2015-06-19 17:51:05 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2015-06-19 17:51:05 +0000 |
commit | a46fb43c1f90054ea0c9a802fc7fb730499c9494 (patch) | |
tree | 4d8bbfeecfc1953c26fd160b3b984c7660a25998 /test/FixIt | |
parent | 24bda7824b760a6f4c4c932772a90639b2c19d92 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240146 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/FixIt')
-rw-r--r-- | test/FixIt/fixit-nullability-declspec.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/FixIt/fixit-nullability-declspec.cpp b/test/FixIt/fixit-nullability-declspec.cpp new file mode 100644 index 0000000000..2ac20b9d9b --- /dev/null +++ b/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?}} |