// RUN: %clang_cc1 -fsyntax-only -fblocks -Wnullable-to-nonnull-conversion -Wno-nullability-declspec %s -verify
typedef int * int_ptr;
// Parse nullability type specifiers.
// This note requires C11.
// expected-note@+2{{'_Nonnull' specified here}}
typedef int * _Nonnull nonnull_int_ptr;
typedef int * _Nullable nullable_int_ptr;
typedef int * _Null_unspecified null_unspecified_int_ptr;
// Redundant nullability type specifiers.
typedef int * _Nonnull _Nonnull redundant_1; // expected-warning{{duplicate nullability specifier '_Nonnull'}}
// Conflicting nullability type specifiers.
typedef int * _Nonnull _Nullable conflicting_1; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
typedef int * _Null_unspecified _Nonnull conflicting_2; // expected-error{{nullability specifier '_Nonnull' conflicts with existing specifier '_Null_unspecified'}}
// Redundant nullability specifiers via a typedef are okay.
typedef nonnull_int_ptr _Nonnull redundant_okay_1;
// Conflicting nullability specifiers via a typedef are not.
// Some of these errors require C11.
typedef nonnull_int_ptr _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
typedef nonnull_int_ptr nonnull_int_ptr_typedef;
typedef nonnull_int_ptr_typedef _Nullable conflicting_2; // expected-error{{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
typedef nonnull_int_ptr_typedef nonnull_int_ptr_typedef_typedef;
typedef nonnull_int_ptr_typedef_typedef _Null_unspecified conflicting_3; // expected-error{{nullability specifier '_Null_unspecified' conflicts with existing specifier '_Nonnull'}}
// Nullability applies to all pointer types.
typedef int ;
typedef int ;
// Nullability must be on a pointer type.
typedef int _Nonnull int_type_1; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
// Nullability can move out to a pointer/block pointer declarator
// (with a suppressed warning).
typedef _Nonnull int * nonnull_int_ptr_2;
typedef int _Nullable * nullable_int_ptr_2;
typedef _Nonnull int ;
typedef _Nonnull int ;
typedef _Nonnull int * * _Nullable nonnull_int_ptr_ptr_1;
typedef _Nonnull int *;
typedef _Nonnull int *;
typedef _Nonnull ;
typedef _Nonnull ;
typedef void ;
void ;
void ;
void
// Moving nullability where it creates a conflict.
typedef _Nonnull int * _Nullable * conflict_int_ptr_ptr_2; // expected-error{{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
// Nullability is not part of the canonical type.
typedef int * _Nonnull ambiguous_int_ptr;
// Redefining a typedef is a C11 feature.
typedef int * ambiguous_int_ptr;
typedef int * _Nullable ambiguous_int_ptr;
// Printing of nullability.
float f;
int * _Nonnull ip_1 = &f; // expected-warning{{incompatible pointer types initializing 'int * _Nonnull' with an expression of type 'float *'}}
// Check printing of nullability specifiers.
void
// Check passing null to a _Nonnull argument.
void ;
;
;
void
// Check returning nil from a _Nonnull-returning function.
_Nonnull int *
// Check nullable-to-nonnull conversions.
void
// Check nullability of conditional expressions.
void
// Check nullability of binary conditional expressions.
void
extern int GLOBAL_LENGTH;
// Nullability can appear on arrays when the arrays are in parameter lists.
void ;
void
int notInFunction; // expected-error {{nullability specifier '_Nullable' cannot be applied to non-pointer type 'int[3]'}}
void // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int[1]'}}
void // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int[1][2]'}}
void // ok
void ; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int'}}
typedef int INTS;
typedef int BAD_INTS; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'int[4]'}}
void ;
INTS _Nonnull x; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int[4]')}}
_Nonnull INTS x; // expected-error {{nullability specifier '_Nonnull' cannot be applied to non-pointer type 'INTS' (aka 'int[4]')}}
void