1 // RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11 \
2 // RUN: -analyzer-checker=deadcode.DeadStores -Wno-unreachable-code \
3 // RUN: -analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false\
4 // RUN: -verify=non-nested %s
6 // RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11 \
7 // RUN: -analyzer-store=region -analyzer-checker=deadcode.DeadStores \
8 // RUN: -analyzer-config deadcode.DeadStores:WarnForDeadNestedAssignments=false\
9 // RUN: -Wno-unreachable-code -verify=non-nested %s
11 // RUN: %clang_analyze_cc1 -fcxx-exceptions -fexceptions -fblocks -std=c++11 \
12 // RUN: -analyzer-checker=deadcode.DeadStores -Wno-unreachable-code \
13 // RUN: -verify=non-nested,nested %s
15 //===----------------------------------------------------------------------===//
16 // Basic dead store checking (but in C++ mode).
17 //===----------------------------------------------------------------------===//
23 x
= x
+ 1; // non-nested-warning {{never read}}
34 if ((y
= make_int())) // nested-warning {{Although the value stored}}
38 //===----------------------------------------------------------------------===//
39 // Dead store checking involving constructors.
40 //===----------------------------------------------------------------------===//
46 Test2(int &y
) : x(y
) {}
51 { Test2
a(x
); } // no-warning
55 //===----------------------------------------------------------------------===//
56 // Dead store checking involving CXXTemporaryExprs
57 //===----------------------------------------------------------------------===//
60 template<typename _Tp
>
65 template<typename _Tp
, typename _Number2
> struct _Row_base
{
66 _Row_base(const pencil
<_Tp
>& x
) {}
68 template<typename _Tp
, typename _Number2
= TestTemp::pencil
<_Tp
> >
69 class row
: protected _Row_base
<_Tp
, _Number2
> {
70 typedef _Row_base
<_Tp
, _Number2
> _Base
;
71 typedef _Number2 pencil_type
;
73 explicit row(const pencil_type
& __a
= pencil_type()) : _Base(__a
) {}
78 TestTemp::row
<const char*> x
; // no-warning
81 //===----------------------------------------------------------------------===//
83 //===----------------------------------------------------------------------===//
86 x
= x
+ 1; // non-nested-warning {{never read}}
89 void test3_b(int &x
) {
90 x
= x
+ 1; // no-warning
95 // Shows the limitation of dead stores tracking. The write is really dead
96 // since the value cannot escape the function.
100 void test3_d(int &x
) {
105 void test3_e(int &x
) {
109 //===----------------------------------------------------------------------===//
110 // Dead stores involving 'new'
111 //===----------------------------------------------------------------------===//
113 static void test_new(unsigned n
) {
114 char **p
= new char *[n
]; // non-nested-warning {{never read}}
117 //===----------------------------------------------------------------------===//
118 // Dead stores in namespaces.
119 //===----------------------------------------------------------------------===//
123 x
= 2; // non-nested-warning {{Value stored to 'x' is never read}}
129 //===----------------------------------------------------------------------===//
130 // Dead stores in with EH code.
131 //===----------------------------------------------------------------------===//
145 int test_6_aux(unsigned x
);
147 unsigned currDestLen
= 0; // no-warning
149 while (test_6_aux(currDestLen
)) {
150 currDestLen
+= 2; // no-warning
157 unsigned currDestLen
= 0; // no-warning
159 while (test_6_aux(currDestLen
)) {
161 // non-nested-warning@-1 {{Value stored to 'currDestLen' is never read}}
168 void testCXX11Using() {
171 value
= 1; // non-nested-warning {{never read}}
174 //===----------------------------------------------------------------------===//
175 // Dead stores in template instantiations (do not warn).
176 //===----------------------------------------------------------------------===//
178 template <bool f
> int radar13213575_testit(int i
) {
179 int x
= 5+i
; // warning: Value stored to 'x' during its initialization is never read
187 int radar_13213575() {
188 return radar13213575_testit
<true>(5) + radar13213575_testit
<false>(3);
192 void test_block_in_dependent_context(typename
T::some_t someArray
) {
194 int i
= someArray
[0]; // no-warning
198 void test_block_in_non_dependent_context(int *someArray
) {
200 int i
= someArray
[0];
201 // non-nested-warning@-1 {{Value stored to 'i' during its initialization is never read}}
206 //===----------------------------------------------------------------------===//
207 // Dead store checking involving lambdas.
208 //===----------------------------------------------------------------------===//
210 int basicLambda(int i
, int j
) {