Skip to content

Commit 40e49a3

Browse files
committed
remove void initilization, make code more safe
1 parent 0c4b824 commit 40e49a3

File tree

7 files changed

+38
-38
lines changed

7 files changed

+38
-38
lines changed

source/mir/math/sum.d

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unittest
5151
Quaternion opBinary(string op)(auto ref const Quaternion rhs) const
5252
if (op == "+" || op == "-")
5353
{
54-
Quaternion ret = void;
54+
Quaternion ret ;
5555
foreach (i, ref e; ret.rijk)
5656
mixin("e = rijk[i] "~op~" rhs.rijk[i];");
5757
return ret;
@@ -446,7 +446,7 @@ struct Summator(T, Summation summation)
446446
static import std.math;
447447
private:
448448
enum F M = (cast(F)(2)) ^^ (T.max_exp - 1);
449-
F[16] scopeBufferArray = void;
449+
F[16] scopeBufferArray = 0;
450450
ScopeBuffer!F partials;
451451
//sum for NaN and infinity.
452452
F s;
@@ -472,7 +472,7 @@ struct Summator(T, Summation summation)
472472
}
473473
body
474474
{
475-
bool _break = void;
475+
bool _break;
476476
foreach_reverse (i, y; partials)
477477
{
478478
s = partialsReducePred(s, y, i ? partials[i-1] : 0, _break);
@@ -554,23 +554,23 @@ struct Summator(T, Summation summation)
554554
else
555555
static if (summation == Summation.kb2)
556556
{
557-
F s = void;
558-
F cs = void;
559-
F ccs = void;
557+
F s = 0;
558+
F cs = 0;
559+
F ccs = 0;
560560
}
561561
else
562562
static if (summation == Summation.kbn)
563563
{
564-
F s = void;
565-
F c = void;
564+
F s = 0;
565+
F c = 0;
566566
}
567567
else
568568
static if (summation == Summation.kahan)
569569
{
570-
F s = void;
571-
F c = void;
572-
F y = void; // do not declare in the loop/put (algo can be used for matrixes and etc)
573-
F t = void; // ditto
570+
F s = F.init;
571+
F c = F.init;
572+
F y = F.init; // do not declare in the loop/put (algo can be used for matrixes and etc)
573+
F t = F.init; // ditto
574574
}
575575
else
576576
static if (summation == Summation.pairwise)
@@ -580,22 +580,22 @@ struct Summator(T, Summation summation)
580580
static if (fastPairwise)
581581
{
582582
enum registersCount= 16;
583-
F[size_t.sizeof * 8] partials = void;
583+
F[size_t.sizeof * 8] partials = F.init;
584584
}
585585
else
586586
{
587-
F[size_t.sizeof * 8] partials = void;
587+
F[size_t.sizeof * 8] partials = F.init;
588588
}
589589
}
590590
else
591591
static if (summation == Summation.naive)
592592
{
593-
F s = void;
593+
F s = F.init;
594594
}
595595
else
596596
static if (summation == Summation.fast)
597597
{
598-
F s = void;
598+
F s = F.init;
599599
}
600600
else
601601
static assert(0, "Unsupported summation type for std.numeric.Summator.");
@@ -759,7 +759,7 @@ public:
759759
static if (isFloatingPoint!F)
760760
{
761761
F t = s + x;
762-
F c = void;
762+
F c = 0;
763763
if (fabs(s) >= fabs(x))
764764
{
765765
F d = s - t;
@@ -911,7 +911,7 @@ public:
911911
{
912912
static if (summation == Summation.pairwise && fastPairwise && isDynamicArray!Range)
913913
{
914-
F[registersCount] v = void;
914+
F[registersCount] v;
915915
foreach (i, n; chainSeq!registersCount)
916916
{
917917
if (r.length >= n * 2) do
@@ -1180,7 +1180,7 @@ public:
11801180
else
11811181
static if (summation == Summation.precise)
11821182
{
1183-
typeof(return) ret = void;
1183+
auto ret = typeof(return).init;
11841184
ret.s = s;
11851185
ret.o = o;
11861186
ret.partials = scopeBuffer(ret.scopeBufferArray);
@@ -1204,7 +1204,7 @@ public:
12041204
else
12051205
static if (summation == Summation.kb2)
12061206
{
1207-
typeof(return) ret = void;
1207+
auto ret = typeof(return).init;
12081208
ret.s = s;
12091209
ret.cs = cs;
12101210
ret.ccs = ccs;
@@ -1213,23 +1213,23 @@ public:
12131213
else
12141214
static if (summation == Summation.kbn)
12151215
{
1216-
typeof(return) ret = void;
1216+
auto ret = typeof(return).init;
12171217
ret.s = s;
12181218
ret.c = c;
12191219
return ret;
12201220
}
12211221
else
12221222
static if (summation == Summation.kahan)
12231223
{
1224-
typeof(return) ret = void;
1224+
auto ret = typeof(return).init;
12251225
ret.s = s;
12261226
ret.c = c;
12271227
return ret;
12281228
}
12291229
else
12301230
static if (summation == Summation.pairwise)
12311231
{
1232-
typeof(return) ret = void;
1232+
auto ret = typeof(return).init;
12331233
ret.counter = counter;
12341234
ret.index = index;
12351235
foreach (i; 0 .. index)
@@ -1239,14 +1239,14 @@ public:
12391239
else
12401240
static if (summation == Summation.naive)
12411241
{
1242-
typeof(return) ret = void;
1242+
auto ret = typeof(return).init;
12431243
ret.s = s;
12441244
return ret;
12451245
}
12461246
else
12471247
static if (summation == Summation.fast)
12481248
{
1249-
typeof(return) ret = void;
1249+
auto ret = typeof(return).init;
12501250
ret.s = s;
12511251
return ret;
12521252
}

source/mir/ndslice/allocation.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ auto shape(T)(T[] array, ref int err)
391391
}
392392
else
393393
{
394-
size_t[1] ret = void;
394+
size_t[1] ret;
395395
ret[0] = array.length;
396396
}
397397
err = 0;

source/mir/ndslice/concatenation.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ struct Concatenation(size_t dim, Slices...)
201201
/// Shape of the concatenation.
202202
size_t[N] shape()() const @property
203203
{
204-
typeof(return) ret = void;
204+
typeof(return) ret;
205205
foreach(i; Iota!N)
206206
ret[i] = length!i;
207207
return ret;
@@ -394,7 +394,7 @@ template pad(size_t[] dimensions, string[] directions)
394394
enum q = directions[$ - 1];
395395
enum N = typeof(S.shape).length;
396396

397-
size_t[N] len = void;
397+
size_t[N] len;
398398
auto _len = s.shape;
399399
foreach(i; Iota!(len.length))
400400
static if (i != d)

source/mir/ndslice/field.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct ndIotaField(size_t N)
264264

265265
size_t[N] opIndex()(size_t index) const
266266
{
267-
size_t[N] indexes = void;
267+
size_t[N] indexes;
268268
foreach_reverse (i; Iota!(N - 1))
269269
{
270270
indexes[i + 1] = index % _lengths[i];
@@ -309,7 +309,7 @@ struct LinspaceField(T)
309309

310310
size_t[1] shape()() @property
311311
{
312-
size_t[1] ret = void;
312+
size_t[1] ret;
313313
ret[0] = _length;
314314
return ret;
315315
}

source/mir/ndslice/internal.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ mixin template _DefineRet_()
111111
static if (hasElaborateAssign!(typeof(Ret._iterator)))
112112
Ret ret;
113113
else
114-
Ret ret = void;
114+
Ret ret = Ret.init;
115115
}
116116

117117

@@ -277,4 +277,4 @@ pure nothrow unittest
277277
assert(lengthsProduct([3, 4, 5]) == 60);
278278
}
279279

280-
struct _Slice() { size_t i = void, j = void; }
280+
struct _Slice() { size_t i, j; }

source/mir/ndslice/ndfield.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct Cartesian(NdFields...)
7474
///
7575
size_t[N] shape()() @property
7676
{
77-
typeof(return) ret = void;
77+
typeof(return) ret;
7878
foreach(f, ref field; _fields)
7979
{
8080
static if (hasShape!(NdFields[f]))
@@ -163,7 +163,7 @@ struct Kronecker(alias fun, NdFields...)
163163
}
164164
else
165165
{
166-
size_t[1] ret = void;
166+
size_t[1] ret;
167167
ret[0] = _fields[0].length;
168168
foreach(ref field; _fields[1 .. $])
169169
ret[0] *= field.length;
@@ -184,9 +184,9 @@ struct Kronecker(alias fun, NdFields...)
184184
auto ref opIndex()(size_t[N] indexes...)
185185
{
186186
static if (N > 1)
187-
size_t[N][NdFields.length] ind = void;
187+
size_t[N][NdFields.length] ind;
188188
else
189-
size_t[NdFields.length] ind = void;
189+
size_t[NdFields.length] ind;
190190
foreach_reverse (f, ref field; _fields)
191191
{
192192
static if (f)
@@ -197,7 +197,7 @@ struct Kronecker(alias fun, NdFields...)
197197
}
198198
else
199199
{
200-
size_t[1] s = void;
200+
size_t[1] s;
201201
s[0] = field.length;
202202
}
203203
static if (N > 1)

source/mir/ndslice/topology.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ See_also: $(LREF)
17121712
auto linspace(T, size_t N)(size_t[N] lengths, T[2][N] intervals...)
17131713
if (N && (isFloatingPoint!T || isComplex!T))
17141714
{
1715-
Repeat!(N, LinspaceField!T) fields = void;
1715+
Repeat!(N, LinspaceField!T) fields;
17161716
foreach(i; Iota!N)
17171717
{
17181718
assert(lengths[i] > 1, "linspace: all lengths must be greater then 1.");

0 commit comments

Comments
 (0)