1 | // RUN: %clang_cc1 -fsyntax-only -fblocks -std=gnu++11 -I %S/Inputs -verify %s |
2 | // RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -fblocks -std=gnu++11 -I %S/Inputs %s >%t.txt 2>&1 |
3 | // RUN: FileCheck %s < %t.txt |
4 | // RUN: FileCheck %S/Inputs/nullability.h < %t.txt |
5 | // RUN: FileCheck %S/Inputs/nullability-objc.h < %t.txt |
6 | |
7 | #include "nullability.h" |
8 | #include "nullability-objc.h" |
9 | |
10 | #pragma clang assume_nonnull begin |
11 | |
12 | extern void *array[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
13 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull " |
14 | |
15 | extern void* array2[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
16 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:13-[[@LINE-1]]:13}:" _Nonnull" |
17 | |
18 | extern void *nestedArray[2][3]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
19 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull " |
20 | |
21 | // No fix-its on either the macro definition or instantiation. |
22 | // CHECK-NOT: fix-it:"{{.*}}nullability.mm":{[[@LINE+2]] |
23 | // CHECK-NOT: fix-it:"{{.*}}nullability.mm":{[[@LINE+2]] |
24 | #define PTR(X) X * |
25 | extern PTR(void) array[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
26 | |
27 | |
28 | typedef const void *CFTypeRef; |
29 | |
30 | extern CFTypeRef typedefArray[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
31 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:17-[[@LINE-1]]:17}:" _Nonnull" |
32 | |
33 | |
34 | extern void *&ref; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
35 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" |
36 | |
37 | extern void * &ref2; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
38 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull" |
39 | |
40 | extern void *&&ref3; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
41 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" |
42 | |
43 | extern void * &&ref4; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
44 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull" |
45 | |
46 | extern void *(&arrayRef)[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
47 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:"_Nonnull" |
48 | |
49 | extern void * (&arrayRef2)[2]; // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
50 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:14-[[@LINE-1]]:14}:" _Nonnull" |
51 | |
52 | extern CFTypeRef &typedefRef; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
53 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:17-[[@LINE-1]]:17}:" _Nonnull" |
54 | extern CFTypeRef& typedefRef2; // expected-warning {{inferring '_Nonnull' for pointer type within reference is deprecated}} |
55 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:17-[[@LINE-1]]:17}:" _Nonnull " |
56 | |
57 | |
58 | void arrayNameless(void *[]); // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
59 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"_Nonnull" |
60 | |
61 | void arrayNameless2(void * []); // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
62 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:27-[[@LINE-1]]:27}:" _Nonnull" |
63 | |
64 | void arrayNamelessTypedef(CFTypeRef[]); // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
65 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:36-[[@LINE-1]]:36}:" _Nonnull " |
66 | |
67 | void arrayNamelessTypedef2(CFTypeRef []); // expected-warning {{inferring '_Nonnull' for pointer type within array is deprecated}} |
68 | // CHECK: fix-it:"{{.*}}nullability.mm":{[[@LINE-1]]:37-[[@LINE-1]]:37}:" _Nonnull" |
69 | |
70 | |
71 | extern int (*pointerToArray)[2]; // no-warning |
72 | int checkTypePTA = pointerToArray; // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type 'int (* _Nonnull)[2]'}} |
73 | |
74 | int **arrayOfNestedPointers[2]; // no-warning |
75 | int checkTypeANP = arrayOfNestedPointers; // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type 'int **[2]'}} |
76 | |
77 | CFTypeRef *arrayOfNestedPointersTypedef[2]; // no-warning |
78 | int checkTypeANPT = arrayOfNestedPointersTypedef; // expected-error {{cannot initialize a variable of type 'int' with an lvalue of type 'CFTypeRef *[2]'}} |
79 | |
80 | #pragma clang assume_nonnull end |
81 | |