blob: 391675fed77b9df2b56f82e706507a72649537a6 [file] [log] [blame]
Douglas Gregor261a89b2015-06-19 17:51:05 +00001// RUN: %clang_cc1 -std=c++11 -fsyntax-only -Wno-nullability-declspec %s -verify
2
3typedef decltype(nullptr) nullptr_t;
4
5class X {
6};
7
8// Nullability applies to all pointer types.
9typedef int (X::* __nonnull member_function_type_1)(int);
10typedef int X::* __nonnull member_data_type_1;
11typedef nullptr_t __nonnull nonnull_nullptr_t; // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'nullptr_t'}}
12
13// Nullability can move into member pointers (this is suppressing a warning).
14typedef __nonnull int (X::* member_function_type_2)(int);
15typedef int (X::* __nonnull member_function_type_3)(int);
16typedef __nonnull int X::* member_data_type_2;
17
18// Adding non-null via a template.
19template<typename T>
20struct AddNonNull {
21 typedef __nonnull T type; // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'int'}}
22 // expected-error@-1{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'nullptr_t'}}
23};
24
25typedef AddNonNull<int *>::type nonnull_int_ptr_1;
26typedef AddNonNull<int * __nullable>::type nonnull_int_ptr_2; // FIXME: check that it was overridden
27typedef AddNonNull<nullptr_t>::type nonnull_int_ptr_3; // expected-note{{in instantiation of template class}}
28
29typedef AddNonNull<int>::type nonnull_non_pointer_1; // expected-note{{in instantiation of template class 'AddNonNull<int>' requested here}}
30
31// Non-null checking within a template.
32template<typename T>
33struct AddNonNull2 {
34 typedef __nonnull AddNonNull<T> invalid1; // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'AddNonNull<T>'}}
35 typedef __nonnull AddNonNull2 invalid2; // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'AddNonNull2<T>'}}
36 typedef __nonnull AddNonNull2<T> invalid3; // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'AddNonNull2<T>'}}
37 typedef __nonnull typename AddNonNull<T>::type okay1;
38
39 // Don't move past a dependent type even if we know that nullability
40 // cannot apply to that specific dependent type.
41 typedef __nonnull AddNonNull<T> (*invalid4); // expected-error{{nullability specifier '__nonnull' cannot be applied to non-pointer type 'AddNonNull<T>'}}
42};