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);
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;
22 clang_analyzer_eval(S::CtorInvocationCount
== 0); //expected-warning{{TRUE}}
25 void zeroSizeMultidimensionalArrayStack() {
26 S::CtorInvocationCount
= 0;
27 S::DtorInvocationCount
= 0;
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;
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;
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];
72 auto *arr2
= new S
[0][2];
75 auto *arr3
= new S
[0][2][2];
78 auto *arr4
= new S
[2][2][0];
81 auto *arr5
= new S
[2][0][2];
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;
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}}
105 void zeroSizeArrayLambdaCapture() {
106 S::CtorInvocationCount
= 0;
107 S::DtorInvocationCount
= 0;
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() {
127 int x
= n
; //expected-warning{{Assigned value is garbage or undefined}}
135 void zeroSizeArrayLambdaCaptureUndefined2() {
140 int x
= n
; //expected-warning{{Assigned value is garbage or undefined}}
149 void zeroSizeArrayMember() {
150 S::CtorInvocationCount
= 0;
151 S::DtorInvocationCount
= 0;
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;
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}}
179 void zeroSizeMultidimensionalArrayMember() {
180 S::CtorInvocationCount
= 0;
181 S::DtorInvocationCount
= 0;
187 clang_analyzer_eval(S::CtorInvocationCount
== 0); //expected-warning{{TRUE}}
188 clang_analyzer_eval(S::DtorInvocationCount
== 0); //expected-warning{{TRUE}}