[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / zero-size-non-pod-array.cpp
bloba2117bc80eac89ce3e489091704ed1c383f0c3a7
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++11 -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -std=c++17 -verify %s
4 void clang_analyzer_eval(bool);
6 struct S{
7 static int CtorInvocationCount;
8 static int DtorInvocationCount;
10 S(){CtorInvocationCount++;}
11 ~S(){DtorInvocationCount++;}
14 int S::CtorInvocationCount = 0;
15 int S::DtorInvocationCount = 0;
17 void zeroSizeArrayStack() {
18 S::CtorInvocationCount = 0;
20 S arr[0];
22 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
25 void zeroSizeMultidimensionalArrayStack() {
26 S::CtorInvocationCount = 0;
27 S::DtorInvocationCount = 0;
30 S arr[2][0];
31 S arr2[0][2];
33 S arr3[0][2][2];
34 S arr4[2][2][0];
35 S arr5[2][0][2];
38 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
39 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
42 void zeroSizeArrayStackInLambda() {
43 S::CtorInvocationCount = 0;
44 S::DtorInvocationCount = 0;
46 []{
47 S arr[0];
48 }();
50 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
51 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
54 void zeroSizeArrayHeap() {
55 S::CtorInvocationCount = 0;
56 S::DtorInvocationCount = 0;
58 auto *arr = new S[0];
59 delete[] arr;
61 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
62 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
65 void zeroSizeMultidimensionalArrayHeap() {
66 S::CtorInvocationCount = 0;
67 S::DtorInvocationCount = 0;
69 auto *arr = new S[2][0];
70 delete[] arr;
72 auto *arr2 = new S[0][2];
73 delete[] arr2;
75 auto *arr3 = new S[0][2][2];
76 delete[] arr3;
78 auto *arr4 = new S[2][2][0];
79 delete[] arr4;
81 auto *arr5 = new S[2][0][2];
82 delete[] arr5;
84 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
85 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
88 #if __cplusplus >= 201703L
90 void zeroSizeArrayBinding() {
91 S::CtorInvocationCount = 0;
93 S arr[0];
95 // Note: This is an error in gcc but a warning in clang.
96 // In MSVC the declaration of 'S arr[0]' is already an error
97 // and it doesn't recognize this syntax as a structured binding.
98 auto [] = arr; //expected-warning{{ISO C++17 does not allow a decomposition group to be empty}}
100 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
103 #endif
105 void zeroSizeArrayLambdaCapture() {
106 S::CtorInvocationCount = 0;
107 S::DtorInvocationCount = 0;
109 S arr[0];
111 auto l = [arr]{};
112 [arr]{}();
114 //FIXME: These should be TRUE. We should avoid calling the destructor
115 // of the temporary that is materialized as the lambda.
116 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}} expected-warning{{FALSE}}
117 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}} expected-warning{{FALSE}}
120 // FIXME: Report a warning if the standard is at least C++17.
121 #if __cplusplus < 201703L
122 void zeroSizeArrayLambdaCaptureUndefined1() {
123 S arr[0];
124 int n;
126 auto l = [arr, n]{
127 int x = n; //expected-warning{{Assigned value is garbage or undefined}}
128 (void) x;
131 l();
133 #endif
135 void zeroSizeArrayLambdaCaptureUndefined2() {
136 S arr[0];
137 int n;
139 [arr, n]{
140 int x = n; //expected-warning{{Assigned value is garbage or undefined}}
141 (void) x;
142 }();
145 struct Wrapper{
146 S arr[0];
149 void zeroSizeArrayMember() {
150 S::CtorInvocationCount = 0;
151 S::DtorInvocationCount = 0;
154 Wrapper W;
157 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
158 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
161 void zeroSizeArrayMemberCopyMove() {
162 S::CtorInvocationCount = 0;
163 S::DtorInvocationCount = 0;
166 Wrapper W;
167 Wrapper W2 = W;
168 Wrapper W3 = (Wrapper&&) W2;
171 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
172 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}
175 struct MultiWrapper{
176 S arr[2][0];
179 void zeroSizeMultidimensionalArrayMember() {
180 S::CtorInvocationCount = 0;
181 S::DtorInvocationCount = 0;
184 MultiWrapper MW;
187 clang_analyzer_eval(S::CtorInvocationCount == 0); //expected-warning{{TRUE}}
188 clang_analyzer_eval(S::DtorInvocationCount == 0); //expected-warning{{TRUE}}