diff --git a/etc/c/odbc/sqlext.d b/etc/c/odbc/sqlext.d index c54ce29de1a..f304ae8e855 100644 --- a/etc/c/odbc/sqlext.d +++ b/etc/c/odbc/sqlext.d @@ -119,7 +119,7 @@ enum int SQL_ATTR_ANSI_APP = 115; // * SQL_ACCESS_MODE options * enum : uint { - SQL_MODE_READ_WRITE = 0UL, + SQL_MODE_READ_WRITE, SQL_MODE_READ_ONLY = 1UL, SQL_MODE_DEFAULT = SQL_MODE_READ_WRITE } @@ -127,7 +127,7 @@ enum : uint // * SQL_AUTOCOMMIT options * enum : uint { - SQL_AUTOCOMMIT_OFF = 0UL, + SQL_AUTOCOMMIT_OFF, SQL_AUTOCOMMIT_ON = 1UL, SQL_AUTOCOMMIT_DEFAULT = SQL_AUTOCOMMIT_ON } @@ -138,7 +138,7 @@ enum uint SQL_LOGIN_TIMEOUT_DEFAULT = 15UL; // * SQL_OPT_TRACE options * enum : uint { - SQL_OPT_TRACE_OFF = 0UL, + SQL_OPT_TRACE_OFF, SQL_OPT_TRACE_ON = 1UL, SQL_OPT_TRACE_DEFAULT = SQL_OPT_TRACE_OFF } @@ -148,7 +148,7 @@ immutable char[] SQL_OPT_TRACE_FILE_DEFAULT = r"\SQL.LOG"; // * SQL_ODBC_CURSORS options * enum : uint { - SQL_CUR_USE_IF_NEEDED = 0UL, + SQL_CUR_USE_IF_NEEDED, SQL_CUR_USE_ODBC = 1UL, SQL_CUR_USE_DRIVER = 2UL, SQL_CUR_DEFAULT = SQL_CUR_USE_DRIVER @@ -157,7 +157,7 @@ enum : uint enum { // * values for SQL_ATTR_DISCONNECT_BEHAVIOR * - SQL_DB_RETURN_TO_POOL = 0UL, + SQL_DB_RETURN_TO_POOL, SQL_DB_DISCONNECT = 1UL, SQL_DB_DEFAULT = SQL_DB_RETURN_TO_POOL, @@ -168,7 +168,7 @@ enum // * values for SQL_ATTR_CONNECTION_DEAD * enum int SQL_CD_TRUE = 1L; // * Connection is closed/dead * -enum int SQL_CD_FALSE = 0L; // * Connection is open/available * +enum int SQL_CD_FALSE = 0L; // * Connection is open/available * // * values for SQL_ATTR_ANSI_APP ( ODBC v3.51 ) * enum int SQL_AA_TRUE = 1L; // * the application is an ANSI app * @@ -177,7 +177,7 @@ enum int SQL_AA_FALSE = 0L; // * the application is a Unicode app * // * statement attributes * enum { - SQL_QUERY_TIMEOUT = 0, + SQL_QUERY_TIMEOUT, SQL_MAX_ROWS = 1, SQL_NOSCAN = 2, SQL_MAX_LENGTH = 3, @@ -238,15 +238,15 @@ enum // * the value of SQL_ATTR_PARAM_BIND_TYPE * enum : uint { - SQL_PARAM_BIND_BY_COLUMN = 0UL, + SQL_PARAM_BIND_BY_COLUMN, SQL_PARAM_BIND_TYPE_DEFAULT = SQL_PARAM_BIND_BY_COLUMN } // * SQL_QUERY_TIMEOUT options * -enum uint SQL_QUERY_TIMEOUT_DEFAULT = 0UL; +enum uint SQL_QUERY_TIMEOUT_DEFAULT = 0L; // * SQL_MAX_ROWS options * -enum uint SQL_MAX_ROWS_DEFAULT = 0UL; +enum uint SQL_MAX_ROWS_DEFAULT = 0L; // * SQL_NOSCAN options * enum : uint @@ -257,7 +257,7 @@ enum : uint } // * SQL_MAX_LENGTH options * -enum uint SQL_MAX_LENGTH_DEFAULT = 0UL; +enum uint SQL_MAX_LENGTH_DEFAULT = 0L; // * values for SQL_ATTR_ASYNC_ENABLE * enum : uint @@ -298,7 +298,7 @@ enum : uint enum uint SQL_ROWSET_SIZE_DEFAULT = 1UL; // * SQL_KEYSET_SIZE options * -enum uint SQL_KEYSET_SIZE_DEFAULT = 0UL; +enum uint SQL_KEYSET_SIZE_DEFAULT = 0L; // * SQL_SIMULATE_CURSOR options * enum : uint @@ -527,7 +527,7 @@ enum SQL_C_GUID = SQL_GUID /* GUID */ } -enum int SQL_TYPE_NULL = 0; +enum int SQL_TYPE_NULL = 0L; // * define for SQL_DIAG_ROW_NUMBER and SQL_DIAG_COLUMN_NUMBER * enum : uint @@ -1642,7 +1642,7 @@ enum ' defined in sql.d ' +/ -enum int SQL_TABLE_STAT = 0; +enum int SQL_TABLE_STAT = 0L; // * Defines for SQLTables * immutable char[] SQL_ALL_CATALOGS = "%"; diff --git a/etc/c/zlib.d b/etc/c/zlib.d index b3e9783389c..93dee398c22 100644 --- a/etc/c/zlib.d +++ b/etc/c/zlib.d @@ -227,7 +227,7 @@ enum } /* The deflate compression method (the only one supported in this version) */ -const int Z_NULL = 0; /* for initializing zalloc, zfree, opaque */ +const int Z_NULL; /* for initializing zalloc, zfree, opaque */ /* basic functions */ diff --git a/std/algorithm/iteration.d b/std/algorithm/iteration.d index 74eba6c3447..20763aa6152 100644 --- a/std/algorithm/iteration.d +++ b/std/algorithm/iteration.d @@ -168,7 +168,7 @@ if (isBidirectionalRange!Range) import std.range, std.stdio; import std.typecons : tuple; - ulong counter = 0; + ulong counter; double fun(int x) { ++counter; @@ -221,7 +221,7 @@ same cost or side effects. { import std.algorithm.comparison : equal; import std.range; - int i = 0; + int i; auto r = iota(0, 4).tee!((a){i = a;}, No.pipeOnPop); auto r1 = r.take(3).cache(); @@ -294,7 +294,7 @@ same cost or side effects. { static struct Range { - bool initialized = false; + bool initialized; bool front() @property {return initialized = true;} void popFront() {initialized = false;} enum empty = false; @@ -514,7 +514,7 @@ function. auto sums = [2, 4, 6, 8]; auto products = [1, 4, 9, 16]; - size_t i = 0; + size_t i; foreach (result; [ 1, 2, 3, 4 ].map!("a + a", "a * a")) { assert(result[0] == sums[i]); @@ -905,7 +905,7 @@ public: } else // if (isRangeBinaryIterable!Range) { - size_t i = 0; + size_t i; while (!r.empty) { cast(void) binaryFun!BinaryArgs(i, r.front); @@ -1809,7 +1809,7 @@ if (isForwardRange!Range) { import std.algorithm.comparison : equal; - size_t popCount = 0; + size_t popCount; class RefFwdRange { int[] impl; @@ -2839,7 +2839,7 @@ if (fun.length >= 1) algoFormat("Seed %s does not have the correct amount of fields (should be %s)", Args.stringof, fun.length)); alias E = Select!(isInputRange!R, ElementType!R, ForeachType!R); - static if (mustInitialize) bool initialized = false; + static if (mustInitialize) bool initialized; foreach (/+auto ref+/ E e; r) // @@@4707@@@ { foreach (i, f; binfuns) @@ -3065,14 +3065,14 @@ The number of seeds must be correspondingly increased. @system unittest { - int i = 0; + int i; static struct OpApply { int opApply(int delegate(ref int) dg) { int[] a = [1, 2, 3]; - int res = 0; + int res; foreach (ref e; a) { res = dg(e); @@ -3155,7 +3155,7 @@ private template ReduceSeedType(E) alias ReduceSeedType = Unqual!(typeof(fun(lvalueOf!E, lvalueOf!E))); //Check the Seed type is useable. - ReduceSeedType s = ReduceSeedType.init; + ReduceSeedType s; static assert(is(typeof({ReduceSeedType s = lvalueOf!E;})) && is(typeof(lvalueOf!ReduceSeedType = fun(lvalueOf!ReduceSeedType, lvalueOf!E))), algoFormat( @@ -4240,7 +4240,7 @@ private struct SplitterResult(alias isTerminator, Range) enum fullSlicing = (hasLength!Range && hasSlicing!Range) || isSomeString!Range; private Range _input; - private size_t _end = 0; + private size_t _end; static if (!fullSlicing) private Range _next; @@ -4717,7 +4717,7 @@ if (isInputRange!R && !isInfinite!R) // elsewhere in std.algorithm and std.range on 64 bit platforms. The 16 in log2(16) comes // from the manual unrolling in sumPairWise16 F[64] store = void; - size_t idx = 0; + size_t idx; void collapseStore(T)(T k) { @@ -4744,7 +4744,7 @@ if (isInputRange!R && !isInfinite!R) ++idx; } - size_t i = 0; + size_t i; foreach (el; data) { store[idx] = el; @@ -4755,7 +4755,7 @@ if (isInputRange!R && !isInfinite!R) } else { - size_t k = 0; + size_t k; while (!data.empty) { store[idx] = sumPairwiseN!(16, true, F)(data); diff --git a/std/algorithm/mutation.d b/std/algorithm/mutation.d index 49f3c850c7f..37cfa41f9b8 100644 --- a/std/algorithm/mutation.d +++ b/std/algorithm/mutation.d @@ -1121,7 +1121,7 @@ pure nothrow @safe @nogc unittest // Issue 5661 test(1) static struct S3 { - static struct X { int n = 0; ~this(){n = 0;} } + static struct X { int n; ~this(){n = 0;} } X x; } static assert(hasElaborateDestructor!S3); @@ -1134,7 +1134,7 @@ pure nothrow @safe @nogc unittest // Issue 5661 test(2) static struct S4 { - static struct X { int n = 0; this(this){n = 0;} } + static struct X { int n; this(this){n = 0;} } X x; } static assert(hasElaborateCopyConstructor!S4); @@ -1233,7 +1233,7 @@ private T moveImpl(T)(ref T source) // Issue 5661 test(1) static struct S3 { - static struct X { int n = 0; ~this(){n = 0;} } + static struct X { int n; ~this(){n = 0;} } X x; } static assert(hasElaborateDestructor!S3); @@ -1246,7 +1246,7 @@ private T moveImpl(T)(ref T source) // Issue 5661 test(2) static struct S4 { - static struct X { int n = 0; this(this){n = 0;} } + static struct X { int n; this(this){n = 0;} } X x; } static assert(hasElaborateCopyConstructor!S4); @@ -1268,7 +1268,7 @@ private T moveImpl(T)(ref T source) @system unittest { - static struct S { int n = 0; ~this() @system { n = 0; } } + static struct S { int n; ~this() @system { n = 0; } } S a, b; static assert(!__traits(compiles, () @safe { move(a, b); })); static assert(!__traits(compiles, () @safe { move(a); })); @@ -1775,9 +1775,9 @@ if (s != SwapStrategy.stable } } - size_t left = 0, right = offset.length - 1; + size_t left, right = offset.length - 1; auto tgt = range.save; - size_t tgtPos = 0; + size_t tgtPos; while (left <= right) { @@ -2167,7 +2167,7 @@ if (isRandomAccessRange!Range && hasLength!Range) //swapAt is in fact the only way to swap non lvalue ranges immutable last = r.length-1; immutable steps = r.length/2; - for (size_t i = 0; i < steps; i++) + for (size_t i; i < steps; i++) { r.swapAt(i, last-i); } @@ -2175,7 +2175,7 @@ if (isRandomAccessRange!Range && hasLength!Range) @safe unittest { - int[] range = null; + int[] range; reverse(range); range = [ 1 ]; reverse(range); @@ -2209,7 +2209,7 @@ if (isNarrowString!(Char[]) && !is(Char == const) && !is(Char == immutable)) import std.utf : stride; auto r = representation(s); - for (size_t i = 0; i < s.length; ) + for (size_t i; i < s.length; ) { immutable step = stride(s, i); if (step > 1) diff --git a/std/algorithm/searching.d b/std/algorithm/searching.d index 72a6f341d39..485929e7e26 100644 --- a/std/algorithm/searching.d +++ b/std/algorithm/searching.d @@ -303,7 +303,7 @@ is ignored. { import std.algorithm.comparison : equal; ptrdiff_t virtual_begin = needle.length - offset - portion; - ptrdiff_t ignore = 0; + ptrdiff_t ignore; if (virtual_begin < 0) { ignore = -virtual_begin; @@ -336,7 +336,7 @@ public: this.skip = new size_t[needle.length]; foreach (a; 0 .. needle.length) { - size_t value = 0; + size_t value; while (value < needle.length && !needlematch(needle, a, value)) { @@ -355,7 +355,7 @@ public: if (needle.length > haystack.length) return haystack[$ .. $]; /* Search: */ immutable limit = haystack.length - needle.length; - for (size_t hpos = 0; hpos <= limit; ) + for (size_t hpos; hpos <= limit; ) { size_t npos = needle.length - 1; while (pred(needle[npos], haystack[npos+hpos])) @@ -448,7 +448,7 @@ if (isForwardRange!R1 && isInputRange!R2 && { import std.range : takeExactly; auto result = r1.save; - size_t i = 0; + size_t i; for (; !r1.empty && !r2.empty && binaryFun!pred(r1.front, r2.front); ++i, r1.popFront(), r2.popFront()) @@ -472,9 +472,9 @@ if (isNarrowString!R1 && isInputRange!R2 && auto result = r1.save; immutable len = r1.length; - size_t i = 0; + size_t i; - for (size_t j = 0; i < len && !r2.empty; r2.popFront(), i = j) + for (size_t j; i < len && !r2.empty; r2.popFront(), i = j) { immutable f = decode(r1, j); if (!binaryFun!pred(f, r2.front)) @@ -503,10 +503,10 @@ if (isNarrowString!R1 && isNarrowString!R2) import std.utf : stride, UTFException; immutable limit = min(r1.length, r2.length); - for (size_t i = 0; i < limit;) + for (size_t i; i < limit;) { immutable codeLen = stride(r1, i); - size_t j = 0; + size_t j; for (; j < codeLen && i < limit; ++i, ++j) { @@ -1569,7 +1569,7 @@ if (isInputRange!InputRange && //We choose a manual decoding approach, because it is faster than //the built-in foreach, or doing a front/popFront for-loop. immutable len = haystack.length; - size_t i = 0, next = 0; + size_t i, next; while (next < len) { if (predFun(decode(haystack, next), needle)) @@ -1590,7 +1590,7 @@ if (isInputRange!InputRange && { import core.stdc.string : memchr; - EType* ptr = null; + EType* ptr; //Note: we use "min/max" to handle sign mismatch. if (min(EType.min, needle) == EType.min && max(EType.max, needle) == EType.max) @@ -1762,7 +1762,7 @@ if (isInputRange!InputRange && enum Foo : ubyte { A } assert([Foo.A].find(Foo.A).empty == false); - ubyte x = 0; + ubyte x; assert([x].find(x).empty == false); } @@ -1805,7 +1805,7 @@ if (isInputRange!InputRange) import std.utf : decode; immutable len = haystack.length; - size_t i = 0, next = 0; + size_t i, next; while (next < len) { if (predFun(decode(haystack, next))) @@ -1965,7 +1965,7 @@ if (isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && isBidirectionalRa auto needleFirstElem = needle[0]; auto partitions = haystack.trisect(needleFirstElem); auto firstElemLen = partitions[1].length; - size_t count = 0; + size_t count; if (firstElemLen == 0) return haystack[$ .. $]; @@ -1988,7 +1988,7 @@ if (isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && isBidirectionalRa { immutable lastIndex = needleLength - 1; auto last = needle[lastIndex]; - size_t j = lastIndex, skip = 0; + size_t j = lastIndex, skip; for (; j < haystack.length;) { if (!binaryFun!pred(haystack[j], last)) @@ -1998,7 +1998,7 @@ if (isRandomAccessRange!R1 && hasLength!R1 && hasSlicing!R1 && isBidirectionalRa } immutable k = j - lastIndex; // last elements match - for (size_t i = 0;; ++i) + for (size_t i;; ++i) { if (i == lastIndex) return haystack[k .. haystack.length]; @@ -2184,7 +2184,7 @@ private R1 simpleMindedFind(alias pred, R1, R2)(R1 haystack, scope R2 needle) static if (hasLength!R1) { static if (!hasLength!R2) - size_t estimatedNeedleLength = 0; + size_t estimatedNeedleLength; else immutable size_t estimatedNeedleLength = needle.length; } @@ -2222,7 +2222,7 @@ private R1 simpleMindedFind(alias pred, R1, R2)(R1 haystack, scope R2 needle) } } static if (estimateNeedleLength) - size_t matchLength = 0; + size_t matchLength; for (auto h = haystack.save, n = needle.save; !n.empty; h.popFront(), n.popFront()) @@ -3190,7 +3190,7 @@ if (isInputRange!Range && !isInfinite!Range && } else static if (isAssignable!(UT, T) || (!hasElaborateAssign!UT && isAssignable!UT)) { - UT v = UT.init; + UT v; static if (isAssignable!(UT, T)) v = range.front; else v = cast(UT) range.front; @@ -3599,7 +3599,7 @@ if (isForwardRange!Range && !isInfinite!Range && static if (hasSlicing!Range && isRandomAccessRange!Range && hasLength!Range) { // Prefer index-based access - size_t pos = 0; + size_t pos; foreach (i; 1 .. range.length) { if (binaryFun!pred(range[i], range[pos])) diff --git a/std/algorithm/setops.d b/std/algorithm/setops.d index f948cb0635c..2347baf0dda 100644 --- a/std/algorithm/setops.d +++ b/std/algorithm/setops.d @@ -423,7 +423,7 @@ if (ranges.length >= 2 && // Test case where only one of the ranges is empty: the result should still // be empty. - int[] p=[1], q=[]; + int[] p=[1], q; auto cprod2 = cartesianProduct(p,p,p,q,p); assert(cprod2.empty); foreach (_; cprod2) {} // should not crash diff --git a/std/algorithm/sorting.d b/std/algorithm/sorting.d index e18f2d0d9b7..903a8d23cd0 100644 --- a/std/algorithm/sorting.d +++ b/std/algorithm/sorting.d @@ -454,7 +454,7 @@ if (ss != SwapStrategy.stable && isInputRange!Range && hasSwappableElements!Rang import std.algorithm.mutation : swapAt; // For dynamic arrays prefer index-based manipulation if (!r.length) return r; - size_t lo = 0, hi = r.length - 1; + size_t lo, hi = r.length - 1; for (;;) { for (;;) @@ -634,7 +634,7 @@ if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range) { auto p = r[0]; // Plant the pivot in the end as well as a sentinel - size_t lo = 0, hi = r.length - 1; + size_t lo, hi = r.length - 1; auto save = move(r[hi]); r[hi] = p; // Vacancy is in r[$ - 1] now // Start process @@ -1950,7 +1950,7 @@ if (((ss == SwapStrategy.unstable && (hasSwappableElements!Range || e = uniform(-100, 100, rnd); } - int i = 0; + int i; bool greater2(int a, int b) @safe { return a + i > b + i; } auto greater = &greater2; sort!(greater)(a); @@ -2132,7 +2132,7 @@ package(std) template HeapOps(alias less, Range) bool isHeap()(Range r) { - size_t parent = 0; + size_t parent; foreach (child; 1 .. r.length) { if (lessFun(r[parent], r[child])) return false; @@ -2251,12 +2251,12 @@ private template TimSortImpl(alias pred, R) immutable minTemp = min(range.length / 2, minimalStorage); size_t minGallop = minimalGallop; Slice[stackSize] stack = void; - size_t stackLen = 0; + size_t stackLen; // Allocate temporary memory if not provided by user if (temp.length < minTemp) temp = () @trusted { return uninitializedArray!(T[])(minTemp); }(); - for (size_t i = 0; i < range.length; ) + for (size_t i; i < range.length; ) { // Find length of first run in list size_t runLen = firstRun(range[i .. range.length]); @@ -2370,7 +2370,7 @@ private template TimSortImpl(alias pred, R) for (; sortedLen < range.length; ++sortedLen) { T item = range.moveAt(sortedLen); - size_t lower = 0; + size_t lower; size_t upper = sortedLen; while (upper != lower) { @@ -2487,7 +2487,7 @@ private template TimSortImpl(alias pred, R) // Move first element into place range[0] = range[mid]; - size_t i = 1, lef = 0, rig = mid + 1; + size_t i = 1, lef, rig = mid + 1; size_t count_lef, count_rig; immutable lef_end = temp.length - 1; @@ -2664,7 +2664,7 @@ private template TimSortImpl(alias pred, R) } body { - size_t lower = 0, center = 1, upper = range.length; + size_t lower, center = 1, upper = range.length; alias gap = center; static if (forwardReverse) @@ -3340,7 +3340,7 @@ body // We work with closed intervals! --hi; - size_t left = 0, rite = r.length - 1; + size_t left, rite = r.length - 1; loop: for (;; ++left, --rite) { for (;; ++left) @@ -4132,7 +4132,7 @@ if (isBidirectionalRange!BidirectionalRange && @safe unittest { // Boundary cases: arrays of 0 or 1 element. - int[] a1 = []; + int[] a1; assert(!nextPermutation(a1)); assert(a1 == []); @@ -4324,7 +4324,7 @@ if (isBidirectionalRange!BidirectionalRange && // Ranges of 0 or 1 element have no distinct permutations. if (range.empty) return false; - bool oddParity = false; + bool oddParity; bool ret = true; do { diff --git a/std/array.d b/std/array.d index e3d94ad17ae..e1a8214bf14 100644 --- a/std/array.d +++ b/std/array.d @@ -852,7 +852,7 @@ if (!isSomeString!(T[]) immutable oldLen = array.length; - size_t to_insert = 0; + size_t to_insert; foreach (i, E; U) { static if (is(E : T)) //a single convertible value, not a range @@ -943,7 +943,7 @@ if (isSomeString!(T[]) && allSatisfy!(isCharOrStringOrDcharRange, U)) return ptr; } } - size_t to_insert = 0; + size_t to_insert; //count up the number of *codeunits* to insert foreach (i, E; U) to_insert += codeLength!T(stuff[i]); @@ -1298,7 +1298,7 @@ if (isDynamicArray!S) else { immutable len = s.length, nlen = n * len; - for (size_t i = 0; i < nlen; i += len) + for (size_t i; i < nlen; i += len) { r[i .. i + len] = s[]; } @@ -1374,7 +1374,7 @@ S[] split(S)(S s) @safe pure if (isSomeString!S) { size_t istart; - bool inword = false; + bool inword; S[] result; foreach (i, dchar c ; s) @@ -1960,7 +1960,7 @@ if (isInputRange!RoR && { // Test that the range is iterated only once. import std.algorithm.iteration : map; - int c = 0; + int c; auto j1 = [1, 2, 3].map!(_ => [c++]).join; assert(c == 3); assert(j1 == [0, 1, 2]); @@ -2733,7 +2733,7 @@ if (isDynamicArray!A) { size_t capacity; Unqual!T[] arr; - bool canExtend = false; + bool canExtend; } private Data* _data; diff --git a/std/bigint.d b/std/bigint.d index 861df64b1ce..ff1e664f2c5 100644 --- a/std/bigint.d +++ b/std/bigint.d @@ -47,7 +47,7 @@ struct BigInt { private: BigUint data; // BigInt adds signed arithmetic to BigUint. - bool sign = false; + bool sign; public: /** * Construct a BigInt from a decimal or hexadecimal string. The number must @@ -75,7 +75,7 @@ public: enforce!ConvException(!s.empty, "Can't initialize BigInt with an empty range"); - bool neg = false; + bool neg; bool ok; data = 0UL; @@ -1033,7 +1033,7 @@ Returns: */ string toDecimalString(const(BigInt) x) { - string outbuff=""; + string outbuff; void sink(const(char)[] s) { outbuff ~= s; } x.toString(&sink, "%d"); return outbuff; @@ -1061,7 +1061,7 @@ Returns: */ string toHex(const(BigInt) x) { - string outbuff=""; + string outbuff; void sink(const(char)[] s) { outbuff ~= s; } x.toString(&sink, "%X"); return outbuff; diff --git a/std/bitmanip.d b/std/bitmanip.d index c38a2a8cec4..89007674485 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -188,7 +188,7 @@ private template createFields(string store, size_t offset, Ts...) private ulong getBitsForAlign(ulong a) { - ulong bits = 0; + ulong bits; while ((a & 0x01) == 0) { bits++; @@ -1113,7 +1113,7 @@ public: __gshared size_t x = 0b1100011000; __gshared ba = BitArray(10, &x); ba.sort; - for (size_t i = 0; i < 6; i++) + for (size_t i; i < 6; i++) assert(ba[i] == false); for (size_t i = 6; i < 10; i++) assert(ba[i] == true); @@ -2770,7 +2770,7 @@ if (canSwapEndianness!T && assert(buffer.peek!ushort(2) == 5641); assert(buffer.peek!ubyte(2) == 22); - size_t index = 0; + size_t index; assert(buffer.peek!ushort(&index) == 261); assert(index == 2); @@ -2789,7 +2789,7 @@ if (canSwapEndianness!T && assert(buffer.peek!bool() == false); assert(buffer.peek!bool(1) == true); - size_t index = 0; + size_t index; assert(buffer.peek!bool(&index) == false); assert(index == 1); @@ -2803,7 +2803,7 @@ if (canSwapEndianness!T && assert(buffer.peek!char() == 'a'); assert(buffer.peek!char(1) == 'b'); - size_t index = 0; + size_t index; assert(buffer.peek!char(&index) == 'a'); assert(index == 1); @@ -2818,7 +2818,7 @@ if (canSwapEndianness!T && assert(buffer.peek!wchar(2) == '”'); assert(buffer.peek!wchar(4) == 'ć'); - size_t index = 0; + size_t index; assert(buffer.peek!wchar(&index) == 'ą'); assert(index == 2); @@ -2836,7 +2836,7 @@ if (canSwapEndianness!T && assert(buffer.peek!dchar(4) == '”'); assert(buffer.peek!dchar(8) == 'ć'); - size_t index = 0; + size_t index; assert(buffer.peek!dchar(&index) == 'ą'); assert(index == 4); @@ -2853,7 +2853,7 @@ if (canSwapEndianness!T && assert(buffer.peek!float()== 32.0); assert(buffer.peek!float(4) == 25.0f); - size_t index = 0; + size_t index; assert(buffer.peek!float(&index) == 32.0f); assert(index == 4); @@ -2867,7 +2867,7 @@ if (canSwapEndianness!T && assert(buffer.peek!double() == 32.0); assert(buffer.peek!double(8) == 25.0); - size_t index = 0; + size_t index; assert(buffer.peek!double(&index) == 32.0); assert(index == 8); @@ -2891,7 +2891,7 @@ if (canSwapEndianness!T && assert(buffer.peek!Foo(4) == Foo.two); assert(buffer.peek!Foo(8) == Foo.three); - size_t index = 0; + size_t index; assert(buffer.peek!Foo(&index) == Foo.one); assert(index == 4); @@ -2916,7 +2916,7 @@ if (canSwapEndianness!T && assert(buffer.peek!Bool(0) == Bool.bfalse); assert(buffer.peek!Bool(1) == Bool.btrue); - size_t index = 0; + size_t index; assert(buffer.peek!Bool(&index) == Bool.bfalse); assert(index == 1); @@ -2938,7 +2938,7 @@ if (canSwapEndianness!T && assert(buffer.peek!Float(0) == Float.one); assert(buffer.peek!Float(4) == Float.two); - size_t index = 0; + size_t index; assert(buffer.peek!Float(&index) == Float.one); assert(index == 4); @@ -2960,7 +2960,7 @@ if (canSwapEndianness!T && assert(buffer.peek!Double(0) == Double.one); assert(buffer.peek!Double(8) == Double.two); - size_t index = 0; + size_t index; assert(buffer.peek!Double(&index) == Double.one); assert(index == 8); @@ -3334,7 +3334,7 @@ if (canSwapEndianness!T && { ubyte[] buffer = [0, 0, 0, 0, 0, 0, 0, 0]; - size_t index = 0; + size_t index; buffer.write!ushort(261, &index); assert(buffer == [1, 5, 0, 0, 0, 0, 0, 0]); assert(index == 2); @@ -3367,7 +3367,7 @@ if (canSwapEndianness!T && buffer.write!bool(false, 1); assert(buffer == [1, 0]); - size_t index = 0; + size_t index; buffer.write!bool(false, &index); assert(buffer == [0, 0]); assert(index == 1); @@ -3387,7 +3387,7 @@ if (canSwapEndianness!T && buffer.write!char('b', 1); assert(buffer == [97, 98, 0]); - size_t index = 0; + size_t index; buffer.write!char('a', &index); assert(buffer == [97, 98, 0]); assert(index == 1); @@ -3411,7 +3411,7 @@ if (canSwapEndianness!T && buffer.write!wchar('”', 2); assert(buffer == [1, 5, 32, 29]); - size_t index = 0; + size_t index; buffer.write!wchar('ć', &index); assert(buffer == [1, 7, 32, 29]); assert(index == 2); @@ -3431,7 +3431,7 @@ if (canSwapEndianness!T && buffer.write!dchar('”', 4); assert(buffer == [0, 0, 1, 5, 0, 0, 32, 29]); - size_t index = 0; + size_t index; buffer.write!dchar('ć', &index); assert(buffer == [0, 0, 1, 7, 0, 0, 32, 29]); assert(index == 4); @@ -3451,7 +3451,7 @@ if (canSwapEndianness!T && buffer.write!float(25.0f, 4); assert(buffer == [66, 0, 0, 0, 65, 200, 0, 0]); - size_t index = 0; + size_t index; buffer.write!float(25.0f, &index); assert(buffer == [65, 200, 0, 0, 65, 200, 0, 0]); assert(index == 4); @@ -3471,7 +3471,7 @@ if (canSwapEndianness!T && buffer.write!double(25.0, 8); assert(buffer == [64, 64, 0, 0, 0, 0, 0, 0, 64, 57, 0, 0, 0, 0, 0, 0]); - size_t index = 0; + size_t index; buffer.write!double(25.0, &index); assert(buffer == [64, 57, 0, 0, 0, 0, 0, 0, 64, 57, 0, 0, 0, 0, 0, 0]); assert(index == 8); @@ -3501,7 +3501,7 @@ if (canSwapEndianness!T && buffer.write!Foo(Foo.three, 8); assert(buffer == [0, 0, 0, 10, 0, 0, 0, 20, 0, 0, 0, 30]); - size_t index = 0; + size_t index; buffer.write!Foo(Foo.three, &index); assert(buffer == [0, 0, 0, 30, 0, 0, 0, 20, 0, 0, 0, 30]); assert(index == 4); @@ -3531,7 +3531,7 @@ if (canSwapEndianness!T && buffer.write!Bool(Bool.btrue, 1); assert(buffer == [1, 1]); - size_t index = 0; + size_t index; buffer.write!Bool(Bool.bfalse, &index); assert(buffer == [0, 1]); assert(index == 1); @@ -3557,7 +3557,7 @@ if (canSwapEndianness!T && buffer.write!Float(Float.two, 4); assert(buffer == [66, 0, 0, 0, 65, 200, 0, 0]); - size_t index = 0; + size_t index; buffer.write!Float(Float.two, &index); assert(buffer == [65, 200, 0, 0, 65, 200, 0, 0]); assert(index == 4); @@ -3583,7 +3583,7 @@ if (canSwapEndianness!T && buffer.write!Double(Double.two, 8); assert(buffer == [64, 64, 0, 0, 0, 0, 0, 0, 64, 57, 0, 0, 0, 0, 0, 0]); - size_t index = 0; + size_t index; buffer.write!Double(Double.two, &index); assert(buffer == [64, 57, 0, 0, 0, 0, 0, 0, 64, 57, 0, 0, 0, 0, 0, 0]); assert(index == 8); @@ -3789,8 +3789,8 @@ if (canSwapEndianness!T && isOutputRange!(R, ubyte)) ulong[] values = [42, -11, long.max, 1098911981329L, 16, 255, 19012, 2, 17]; assert(Types.length == values.length); - size_t index = 0; - size_t length = 0; + size_t index; + size_t length; foreach (T; Types) { toWrite.append!(T, endianness)(cast(T) values[index++]); diff --git a/std/compiler.d b/std/compiler.d index 6ceabcefb45..8f5f7210de2 100644 --- a/std/compiler.d +++ b/std/compiler.d @@ -50,9 +50,13 @@ immutable /** - * The version of the D Programming Language Specification + * The major version of the D Programming Language Specification * supported by the compiler. */ uint D_major = 2; + /** + * The minor version of the D Programming Language Specification + * supported by the compiler. + */ uint D_minor = 0; } diff --git a/std/container/array.d b/std/container/array.d index af01deff11e..7553c9e3955 100644 --- a/std/container/array.d +++ b/std/container/array.d @@ -699,7 +699,7 @@ if (!is(Unqual!T == bool)) mixin("slice[i .. j] "~op~"= value;"); } - private enum hasSliceWithLength(T) = is(typeof({ T t = T.init; t[].length; })); + private enum hasSliceWithLength(T) = is(typeof({ T t; t[].length; })); /** * Returns: A new array which is a concatenation of `this` and its argument. @@ -1425,7 +1425,7 @@ if (!is(Unqual!T == bool)) @system unittest //6998 { - static int i = 0; + static int i; class C { int dummy = 1; @@ -2356,7 +2356,7 @@ if (is(Unqual!T == bool)) @system unittest { Array!bool a; - for (int i = 0; i < 100; ++i) + for (int i; i < 100; ++i) a.insertBack(true); foreach (e; a) assert(e); diff --git a/std/container/dlist.d b/std/container/dlist.d index 633371fa67f..f8096ad4d62 100644 --- a/std/container/dlist.d +++ b/std/container/dlist.d @@ -76,8 +76,8 @@ Also used for parts of the code that don't depend on the payload type. +/ private struct BaseNode { - private BaseNode* _prev = null; - private BaseNode* _next = null; + private BaseNode* _prev; + private BaseNode* _next; /+ Gets the payload associated with this node. @@ -194,7 +194,7 @@ struct DList(T) BaseNode _base; alias _base this; - T _payload = T.init; + T _payload; inout(BaseNode)* asBaseNode() inout @trusted { @@ -687,7 +687,7 @@ Complexity: $(BIGOH r.walkLength) assert(r.source._first, "Remove: Range is empty"); BaseNode* first = r.source._first; - BaseNode* last = null; + BaseNode* last; do { last = r.source._first; diff --git a/std/container/rbtree.d b/std/container/rbtree.d index 5342b1692e4..f1640feef91 100644 --- a/std/container/rbtree.d +++ b/std/container/rbtree.d @@ -435,7 +435,7 @@ struct RBNode(V) else x = _right; - bool deferedUnlink = false; + bool deferedUnlink; if (x is null) { // pretend this is a null node, defer unlinking the node @@ -845,7 +845,7 @@ if (is(typeof(binaryFun!less(T.init, T.init)))) static if (allowDuplicates) { inout(RBNode)* cur = _end.left; - inout(RBNode)* result = null; + inout(RBNode)* result; while (cur) { if (_less(cur.value, e)) @@ -1148,7 +1148,7 @@ if (is(typeof(binaryFun!less(T.init, T.init)))) */ size_t stableInsert(Stuff)(Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, Elem)) { - size_t result = 0; + size_t result; static if (allowDuplicates) { foreach (e; stuff) @@ -1636,14 +1636,14 @@ assert(equal(rbt[], [5])); if (n !is null) { printTree(n.right, indent + 2); - for (int i = 0; i < indent; i++) + for (int i; i < indent; i++) write("."); writeln(n.color == n.color.Black ? "B" : "R"); printTree(n.left, indent + 2); } else { - for (int i = 0; i < indent; i++) + for (int i; i < indent; i++) write("."); writeln("N"); } diff --git a/std/conv.d b/std/conv.d index 85a62cfdc08..99ba8a554b2 100644 --- a/std/conv.d +++ b/std/conv.d @@ -2085,7 +2085,7 @@ if (isSomeChar!(ElementType!Source) && // int or larger types static if (Target.min < 0) - bool sign = false; + bool sign; else enum bool sign = false; @@ -2423,7 +2423,7 @@ Lerr: char popFront() { return str[front_index++]; } bool empty() const @property { return str.length <= front_index; } string str; - size_t front_index = 0; + size_t front_index; } auto input = StrInputRange("777"); assert(parse!int(input) == 777); @@ -2481,7 +2481,7 @@ body } } - bool overflow = false; + bool overflow; auto nextv = v.mulu(radix, overflow).addu(c - '0', overflow); enforce!ConvOverflowException(!overflow && nextv <= Target.max, "Overflow in integral conversion"); v = cast(Target) nextv; @@ -2556,7 +2556,7 @@ if (isSomeString!Source && !is(Source == enum) && { import std.algorithm.searching : startsWith; Target result; - size_t longest_match = 0; + size_t longest_match; foreach (i, e; EnumMembers!Target) { @@ -2668,7 +2668,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum enforce(!p.empty, bailOut()); - bool sign = false; + bool sign; switch (p.front) { case '-': @@ -2703,7 +2703,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum default: {} } - bool isHex = false; + bool isHex; bool startsWithZero = p.front == '0'; if (startsWithZero) { @@ -2720,15 +2720,15 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum real ldval = 0.0; char dot = 0; /* if decimal point has been seen */ - int exp = 0; - long msdec = 0, lsdec = 0; + int exp; + long msdec, lsdec; ulong msscale = 1; if (isHex) { - int guard = 0; - int anydigits = 0; - uint ndigits = 0; + int guard; + int anydigits; + uint ndigits; p.popFront(); while (!p.empty) @@ -2999,7 +2999,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum break; default: {} } - bool sawDigits = 0; + bool sawDigits; e = 0; while (!p.empty && isDigit(p.front)) { @@ -3019,7 +3019,7 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum ldval = ldval * msscale + lsdec; if (ldval) { - uint u = 0; + uint u; int pow = 4096; while (exp > 0) @@ -3668,7 +3668,7 @@ if (isExactSomeString!Source && return result; } } - for (size_t i = 0; ; s.popFront(), skipWS(s)) + for (size_t i; ; s.popFront(), skipWS(s)) { if (i == result.length) goto Lmanyerr; @@ -4154,7 +4154,7 @@ private template octalFitsInInt(string octalNum) private string strippedOctalLiteral(string original) { - string stripped = ""; + string stripped; foreach (c; original) if (c >= '0' && c <= '7') stripped ~= c; @@ -4721,7 +4721,7 @@ version(unittest) private class __conv_EmplaceTestClass S2[2] ss2 = void; emplace(&ss1); static assert(!__traits(compiles, emplace(&ss2))); - S1 s1 = S1.init; + S1 s1; S2 s2 = S2.init; static assert(!__traits(compiles, emplace(&ss1, s1))); emplace(&ss2, s2); @@ -5009,7 +5009,7 @@ version(unittest) private class __conv_EmplaceTestClass //Context pointer @system unittest { - int i = 0; + int i; { struct S1 { @@ -5227,7 +5227,7 @@ version(unittest) { static struct S2 { - int i = 0; + int i; static S2 opCall(int*){assert(0);} static S2 opCall(int){assert(0);} this(int i){this.i = i;} @@ -5240,7 +5240,7 @@ version(unittest) { static struct S3 { - int i = 0; + int i; static S3 opCall(ref S3){assert(0);} } S3 s = void; @@ -5283,7 +5283,7 @@ version(unittest) A a; } - B b1 = B.init; + B b1; assert(&b1); // verify that default eyes invariants are ok; auto b2 = B(SysTime(0, UTC()), 1, A(1)); @@ -5344,7 +5344,7 @@ version(unittest) @system unittest { - bool allowDestruction = false; + bool allowDestruction; struct S { int i; @@ -5367,7 +5367,7 @@ version(unittest) @system unittest { //Checks postblit, construction, and context pointer - int count = 0; + int count; struct S { this(this) @@ -5421,7 +5421,7 @@ version(unittest) S[2] ss = void; emplaceRef!(IS[2])(ss, IS()); - IS[2] iss = IS.init; + IS[2] iss; emplaceRef!(IS[2])(ss, iss); emplaceRef!(IS[2])(ss, iss[]); } @@ -5698,7 +5698,7 @@ if (isIntegral!T) { // issue 10874 enum Test { a = 0 } - ulong l = 0; + ulong l; auto t = l.to!Test; } @@ -6030,7 +6030,7 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && { void initialize(UT value) { - bool neg = false; + bool neg; if (value < 10) { if (value >= 0) @@ -6271,7 +6271,7 @@ if ((radix == 2 || radix == 8 || radix == 10 || radix == 16) && // opSlice vs popFront auto r = original.save; - size_t i = 0; + size_t i; for (; !r.empty; r.popFront(), ++i) { assert(original[i .. original.length].tupleof == r.tupleof); diff --git a/std/csv.d b/std/csv.d index a896159b5b0..b77cb5d59ba 100644 --- a/std/csv.d +++ b/std/csv.d @@ -1675,7 +1675,7 @@ if (isSomeChar!Separator && isInputRange!Range 4.0, 5.0, 6.0`; static struct Data { real a, b, c; } - size_t i = 0; + size_t i; foreach (data; csvReader!Data(csv)) with (data) { int[] row = [cast(int) a, cast(int) b, cast(int) c]; diff --git a/std/datetime/package.d b/std/datetime/package.d index 976d06ddb79..9599371a800 100644 --- a/std/datetime/package.d +++ b/std/datetime/package.d @@ -380,7 +380,7 @@ public: private: // true if observing. - bool _flagStarted = false; + bool _flagStarted; // TickDuration at the time of StopWatch starting measurement. TickDuration _timeStart; diff --git a/std/datetime/stopwatch.d b/std/datetime/stopwatch.d index 12605a92045..149bbc81c15 100644 --- a/std/datetime/stopwatch.d +++ b/std/datetime/stopwatch.d @@ -344,7 +344,7 @@ private: // We track the ticks for the elapsed time rather than a Duration so that we // don't lose any precision. - bool _running = false; // Whether the StopWatch is currently running + bool _running; // Whether the StopWatch is currently running MonoTime _timeStarted; // The time the StopWatch started measuring (i.e. when it was started or reset). long _ticksElapsed; // Total time that the StopWatch ran before it was stopped last. } diff --git a/std/datetime/systime.d b/std/datetime/systime.d index 46eee5c8325..2a3e107b1c5 100644 --- a/std/datetime/systime.d +++ b/std/datetime/systime.d @@ -9516,7 +9516,7 @@ DosFileTime SysTimeToDosFileTime(SysTime sysTime) @safe if (dateTime.year > 2107) throw new DateTimeException("DOS File Times cannot hold dates past 2107."); - uint retval = 0; + uint retval; retval = (dateTime.year - 1980) << 25; retval |= (dateTime.month & 0x0F) << 21; retval |= (dateTime.day & 0x1F) << 16; @@ -9610,7 +9610,7 @@ if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && char[4] temp; char[] sliceAsString(R str) @trusted { - size_t i = 0; + size_t i; foreach (c; str) temp[i++] = cast(char) c; return temp[0 .. str.length]; @@ -10537,7 +10537,7 @@ if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && (is(Unqual!(ElementType!R) == char) || is(Unqual!(ElementType!R) == ubyte))) { immutable e = range.length; - outer: for (size_t i = 0; i < e; ) + outer: for (size_t i; i < e; ) { switch (range[i]) { diff --git a/std/datetime/timezone.d b/std/datetime/timezone.d index 066b150b559..a76f3851842 100644 --- a/std/datetime/timezone.d +++ b/std/datetime/timezone.d @@ -2306,12 +2306,12 @@ public: foreach (i, ref ttype; transitionTypes) { - bool isStd = false; + bool isStd; if (i < transitionIsStd.length && !transitionIsStd.empty) isStd = transitionIsStd[i]; - bool inUTC = false; + bool inUTC; if (i < transitionInUTC.length && !transitionInUTC.empty) inUTC = transitionInUTC[i]; @@ -2367,7 +2367,7 @@ public: string stdName; string dstName; - bool hasDST = false; + bool hasDST; foreach (transition; retro(transitions)) { diff --git a/std/digest/md.d b/std/digest/md.d index 8ef7bbcb583..4ec7bc6fadd 100644 --- a/std/digest/md.d +++ b/std/digest/md.d @@ -192,7 +192,7 @@ struct MD5 { import std.bitmanip : littleEndianToNative; - for (size_t i = 0; i < 16; i++) + for (size_t i; i < 16; i++) { x[i] = littleEndianToNative!uint(*cast(ubyte[4]*)&(*block)[i*4]); } diff --git a/std/digest/murmurhash.d b/std/digest/murmurhash.d index 89b4b1cd476..c7118b654df 100644 --- a/std/digest/murmurhash.d +++ b/std/digest/murmurhash.d @@ -154,7 +154,7 @@ struct MurmurHash3(uint size /* 32 or 128 */ , uint opt = size_t.sizeof == 8 ? 6 assert(data.length < Element.sizeof); assert(data.length >= 0); element_count += data.length; - uint k1 = 0; + uint k1; final switch (data.length & 3) { case 3: @@ -231,10 +231,10 @@ struct MurmurHash3(uint size /* 32 or 128 */ , uint opt = size_t.sizeof == 8 ? 6 assert(data.length < Element.sizeof); assert(data.length >= 0); element_count += data.length; - uint k1 = 0; - uint k2 = 0; - uint k3 = 0; - uint k4 = 0; + uint k1; + uint k2; + uint k3; + uint k4; final switch (data.length & 15) { @@ -366,8 +366,8 @@ struct MurmurHash3(uint size /* 32 or 128 */ , uint opt = size_t.sizeof == 8 ? 6 assert(data.length < Element.sizeof); assert(data.length >= 0); element_count += data.length; - ulong k1 = 0; - ulong k2 = 0; + ulong k1; + ulong k2; final switch (data.length & 15) { case 15: diff --git a/std/digest/ripemd.d b/std/digest/ripemd.d index 0dd472c03e4..5bb9e278c2e 100644 --- a/std/digest/ripemd.d +++ b/std/digest/ripemd.d @@ -237,7 +237,7 @@ struct RIPEMD160 { import std.bitmanip : littleEndianToNative; - for (size_t i = 0; i < 16; i++) + for (size_t i; i < 16; i++) { x[i] = littleEndianToNative!uint(*cast(ubyte[4]*)&(*block)[i*4]); } diff --git a/std/encoding.d b/std/encoding.d index 33249e1fb48..fcc9997e0e0 100644 --- a/std/encoding.d +++ b/std/encoding.d @@ -293,7 +293,7 @@ import std.typecons; // Make sure we can sanitize everything bad assert(invalidStrings.length == sanitizedStrings.length); - for (int i=0; i f.precision) len = f.precision; @@ -2924,7 +2924,7 @@ if (isInputRange!T) put(w, val); else { - size_t printed = 0; + size_t printed; for (; !val.empty && printed < f.precision; val.popFront(), ++printed) put(w, val.front); } @@ -3088,7 +3088,7 @@ if (is(StringTypeOf!T) && !is(T == enum)) // ignore other specifications and quote auto app = appender!(typeof(val[0])[])(); put(app, '\"'); - for (size_t i = 0; i < str.length; ) + for (size_t i; i < str.length; ) { import std.utf : decode; @@ -3210,7 +3210,7 @@ if (is(AssocArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char)) enum const(Char)[] defSpec = "%s" ~ f.keySeparator ~ "%s" ~ f.seqSeparator; auto fmtSpec = f.spec == '(' ? f.nested : defSpec; - size_t i = 0; + size_t i; immutable end = val.length; if (f.spec == 's') @@ -3938,7 +3938,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) { string toString() const { return ""; } } - S* p = null; + S* p; formatTest( p, "null" ); S* q = cast(S*) 0xFFEECCAA; @@ -3967,7 +3967,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) @system pure unittest { // Test for issue 11778 - int* p = null; + int* p; assertThrown(format("%d", p)); assertThrown(format("%04d", p + 2)); } @@ -3975,7 +3975,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char)) @safe pure unittest { // Test for issue 12505 - void* p = null; + void* p; formatTest( "%08X", p, "00000000" ); } @@ -4049,7 +4049,7 @@ private void formatNth(Writer, Char, A...)(Writer w, const ref FormatSpec!Char f formatTest( "testing %((%s) %)) wyda3", a, "testing (1) (3) (2) wyda3" ); - int[0] empt = []; + int[0] empt; formatTest( "(%s)", empt, "([])" ); } @@ -4594,7 +4594,7 @@ here: //assert(stream.data == "[3:[h,e,l,l,o],4:[b,e,t,t,y]]"); static const dchar[] ds = ['a','b']; - for (int j = 0; j < ds.length; ++j) + for (int j; j < ds.length; ++j) { stream.clear(); formattedWrite(stream, " %d", ds[j]); if (j == 0) @@ -5225,7 +5225,7 @@ body } const(Char)[] cont = spec.trailing; - for (size_t j = 0; j < spec.trailing.length; ++j) + for (size_t j; j < spec.trailing.length; ++j) { if (spec.trailing[j] == '%') { @@ -5723,7 +5723,7 @@ private bool needToSwapEndianess(Char)(const ref FormatSpec!Char f) assert(r == `[3:"hello", 4:"betty"]` || r == `[4:"betty", 3:"hello"]`); static const dchar[] ds = ['a','b']; - for (int j = 0; j < ds.length; ++j) + for (int j; j < ds.length; ++j) { r = format(" %d", ds[j]); if (j == 0) diff --git a/std/functional.d b/std/functional.d index 128c89c5807..256f906dabb 100644 --- a/std/functional.d +++ b/std/functional.d @@ -1299,7 +1299,7 @@ if (isCallable!(F)) return 8675309; } - uint myNum = 0; + uint myNum; auto incMyNumDel = toDelegate(&inc); auto returnVal = incMyNumDel(myNum); assert(myNum == 1); @@ -1312,7 +1312,7 @@ if (isCallable!(F)) return 8675309; } - uint myNum = 0; + uint myNum; auto incMyNumDel = toDelegate(&inc); int delegate(ref uint) dg = incMyNumDel; auto returnVal = incMyNumDel(myNum); @@ -1447,7 +1447,7 @@ template forward(args...) { auto foo(TL...)(auto ref TL args) { - string result = ""; + string result; foreach (i, _; args) { //pragma(msg, "[",i,"] ", __traits(isRef, args[i]) ? "L" : "R"); diff --git a/std/getopt.d b/std/getopt.d index 890a3c3f233..f14c14dbe25 100644 --- a/std/getopt.d +++ b/std/getopt.d @@ -806,7 +806,7 @@ private bool handleOption(R)(string option, R receiver, ref string[] args, import std.ascii : isAlpha; import std.conv : text, to; // Scan arguments looking for a match for this option - bool ret = false; + bool ret; for (size_t i = 1; i < args.length; ) { auto a = args[i]; @@ -1058,7 +1058,7 @@ dchar assignChar = '='; Defaults to "" but can be assigned to prior to calling $(D getopt). */ -string arraySep = ""; +string arraySep; private enum autoIncrementChar = '+'; @@ -1177,7 +1177,7 @@ private void setConfig(ref configuration cfg, config option) @safe pure nothrow string data = "file.dat"; int length = 24; - bool verbose = false; + bool verbose; args = ["program.name", "--length=5", "--file", "dat.file", "--verbose"]; getopt( args, @@ -1338,7 +1338,7 @@ private void setConfig(ref configuration cfg, config option) @safe pure nothrow @safe unittest // @safe std.getopt.config option use { - long x = 0; + long x; string[] args = ["program", "--inc-x", "--inc-x"]; getopt(args, std.getopt.config.caseSensitive, @@ -1568,7 +1568,7 @@ private void setConfig(ref configuration cfg, config option) @safe pure nothrow scope(exit) endOfOptions = endOfOptionsBackup; endOfOptions = "endofoptions"; string[] args = ["program", "endofoptions", "--option"]; - bool b = false; + bool b; getopt(args, "option", &b); assert(!b); assert(args == ["program", "--option"]); @@ -1620,7 +1620,7 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt) output.formattedWrite("%s\n", text); size_t ls, ll; - bool hasRequired = false; + bool hasRequired; foreach (it; opt) { ls = max(ls, it.optShort.length); @@ -1728,7 +1728,7 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt) @system unittest // Issue 17327 repeated option use { - long num = 0; + long num; string[] args = ["program", "--num", "3"]; getopt(args, "n|num", &num); @@ -1758,7 +1758,7 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt) "add", "Add N to num", &addN,); assert(num == 21); - bool flag = false; + bool flag; args = ["program", "--flag"]; getopt(args, "f|flag", "Boolean", &flag); assert(flag); @@ -1794,8 +1794,8 @@ void defaultGetoptFormatter(Output)(Output output, string text, Option[] opt) return (option, value) => addN(dest, value); } - long x = 0; - long y = 0; + long x; + long y; string[] args = ["program", "--x-plus-1", "--x-plus-1", "--x-plus-5", "--x-plus-n", "10", diff --git a/std/internal/cstring.d b/std/internal/cstring.d index 08b75e4f143..32623ef551e 100644 --- a/std/internal/cstring.d +++ b/std/internal/cstring.d @@ -47,7 +47,7 @@ if (isSomeChar!C) in { assert(cstr); } body { - size_t length = 0; + size_t length; while (cstr[length]) ++length; return cstr[0 .. length]; diff --git a/std/internal/digest/sha_SSSE3.d b/std/internal/digest/sha_SSSE3.d index 547b208bddf..57f4eb539e9 100644 --- a/std/internal/digest/sha_SSSE3.d +++ b/std/internal/digest/sha_SSSE3.d @@ -224,7 +224,7 @@ version(USE_SSSE3) */ private nothrow pure string[] weave(string[] seq1, string[] seq2, uint dist = 1) { - string[] res = []; + string[] res; auto i1 = 0, i2 = 0; while (i1 < seq1.length || i2 < seq2.length) { diff --git a/std/internal/math/biguintcore.d b/std/internal/math/biguintcore.d index 6391a70a9f2..9d23a56c20f 100644 --- a/std/internal/math/biguintcore.d +++ b/std/internal/math/biguintcore.d @@ -312,7 +312,7 @@ public: buff[frontExtraBytes + (extraPad & 7)] = (padChar == ' ' ? ' ' : separator); start += (extraPad & 7) + 1; } - for (int i=0; i< (extraPad >> 3); ++i) + for (int i; i< (extraPad >> 3); ++i) { buff[start .. start + 8] = padChar; buff[start + 8] = (padChar == ' ' ? ' ' : separator); @@ -628,7 +628,7 @@ public: { assert(y != 0, "BigUint division by zero"); // perfect power of 2 - uint b = 0; + uint b; for (;y != 1; y>>=1) { ++b; @@ -756,7 +756,7 @@ public: // Length of the non-zero portion size_t nonzerolength = x.data.length - firstnonzero; ulong y0; - uint evenbits = 0; // number of even bits in the bottom of x + uint evenbits; // number of even bits in the bottom of x while (!(x0 & 1)) { x0 >>= 1; @@ -775,7 +775,7 @@ public: } // Now if (singledigit), x^^y = (x0 ^^ y) * 2^^(evenbits * y) * 2^^(firstnonzero*y*BigDigitBits)) - uint evenshiftbits = 0; // Total powers of 2 to shift by, at the end + uint evenshiftbits; // Total powers of 2 to shift by, at the end // Simplify, step 2: For singledigits, see if we can trivially reduce y @@ -1566,7 +1566,7 @@ private: char [] biguintToHex(char [] buff, const BigDigit [] data, char separator=0, LetterCase letterCase = LetterCase.upper) pure nothrow @safe { - int x=0; + int x; for (ptrdiff_t i=data.length - 1; i >= 0; --i) { toHexZeroPadded(buff[x .. x+8], data[i], letterCase); @@ -1596,8 +1596,8 @@ char [] biguintToHex(char [] buff, const BigDigit [] data, char separator=0, size_t biguintToOctal(char[] buff, const(BigDigit)[] data) pure nothrow @safe @nogc { - ubyte carry = 0; - int shift = 0; + ubyte carry; + int shift; size_t penPos = buff.length - 1; size_t lastNonZero = buff.length - 1; @@ -1716,10 +1716,10 @@ body // TODO: This is inefficient for very large strings (it is O(n^^2)). // We should take advantage of fast multiplication once the numbers exceed // Karatsuba size. - uint lo = 0; // number of powers of digits, 0 .. 18 - uint x = 0; - ulong y = 0; - uint hi = 0; // number of base 1e19 digits + uint lo; // number of powers of digits, 0 .. 18 + uint x; + ulong y; + uint hi; // number of base 1e19 digits data[0] = 0; // initially number is 0. if (data.length > 1) data[1] = 0; @@ -1782,7 +1782,7 @@ body } else { - for (int k=0; k>numbits) + (cast(ulong)(src[i-1]) << (64 - numbits)); @@ -195,7 +195,7 @@ uint multibyteMul(uint[] dest, const(uint)[] src, uint multiplier, uint carry) { assert(dest.length == src.length); ulong c = carry; - for (size_t i = 0; i < src.length; ++i) + for (size_t i; i < src.length; ++i) { c += cast(ulong)(src[i]) * multiplier; dest[i] = cast(uint) c; @@ -222,7 +222,7 @@ uint multibyteMulAdd(char op)(uint [] dest, const(uint)[] src, { assert(dest.length == src.length); ulong c = carry; - for (size_t i = 0; i < src.length; ++i) + for (size_t i; i < src.length; ++i) { static if (op=='+') { @@ -272,7 +272,7 @@ uint multibyteMulAdd(char op)(uint [] dest, const(uint)[] src, void multibyteMultiplyAccumulate(uint [] dest, const(uint)[] left, const(uint) [] right) pure @nogc @safe { - for (size_t i = 0; i < right.length; ++i) + for (size_t i; i < right.length; ++i) { dest[left.length + i] = multibyteMulAdd!('+')(dest[i .. left.length+i], left, right[i], 0); @@ -299,11 +299,11 @@ uint multibyteDivAssign(uint [] dest, uint divisor, uint overflow) @safe unittest { uint [] aa = new uint[101]; - for (uint i = 0; i < aa.length; ++i) + for (uint i; i < aa.length; ++i) aa[i] = 0x8765_4321 * (i+3); uint overflow = multibyteMul(aa, aa, 0x8EFD_FCFB, 0x33FF_7461); uint r = multibyteDivAssign(aa, 0x8EFD_FCFB, overflow); - for (uint i=0; i9 ? ""~ cast(char)('0'+i/10) : "") ~ cast(char)('0' + i%10); - int last = 0; - for (int j = 0; j real.mant_dig-5); if (testpoints[i] (aa/(aa+bb)) ) @@ -1176,7 +1176,7 @@ real betaDistExpansion2(real a, real b, real x ) z = x / (1.0L-x); ans = 1.0L; r = 1.0L; - int n = 0; + int n; const real thresh = 3.0L * real.epsilon; do { diff --git a/std/internal/test/dummyrange.d b/std/internal/test/dummyrange.d index a6bce0ada23..447b022928e 100644 --- a/std/internal/test/dummyrange.d +++ b/std/internal/test/dummyrange.d @@ -427,7 +427,7 @@ if (is(T == TestFoo)) { T it; Cmp.initialize(it.arr); - for (size_t numRuns = 0; numRuns < 2; ++numRuns) + for (size_t numRuns; numRuns < 2; ++numRuns) { if (numRuns == 1) { @@ -454,7 +454,7 @@ if (is(T == TestFoo)) auto cmp = Cmp.iota(1,11); - size_t jdx = 0; + size_t jdx; while (!it.empty && !cmp.empty) { static if (hasLength!T) @@ -501,7 +501,7 @@ if (is(T == TestFoo)) { T it; Cmp.initialize(it.arr); - size_t idx = 0; + size_t idx; foreach (jt; it) { assert(it[idx] == jt); @@ -516,7 +516,7 @@ if (is(T == TestFoo)) { auto copy = it; copy.arr = it.arr.dup; - for (size_t i = 0; i < copy.length; ++i) + for (size_t i; i < copy.length; ++i) { copy[i] = Cmp.dummyValue; copy[i] += Cmp.dummyValue; @@ -528,7 +528,7 @@ if (is(T == TestFoo)) { T copy; copy.arr = it.arr.dup; - for (size_t i = 0; i < copy.length; ++i) + for (size_t i; i < copy.length; ++i) { copy[i] = Cmp.dummyValue; copy[i] += Cmp.dummyValue; diff --git a/std/json.d b/std/json.d index 79c79bb7042..9545390c77b 100644 --- a/std/json.d +++ b/std/json.d @@ -513,7 +513,7 @@ struct JSONValue { enforceEx!JSONException(type == JSON_TYPE.OBJECT || type == JSON_TYPE.NULL, "JSONValue must be object or null"); - JSONValue[string] aa = null; + JSONValue[string] aa; if (type == JSON_TYPE.OBJECT) { aa = this.objectNoRef; @@ -713,7 +713,7 @@ if (isInputRange!T && !isInfinite!T && isSomeChar!(ElementEncodingType!T)) int depth = -1; dchar next = 0; - int line = 1, pos = 0; + int line = 1, pos; void error(string msg) { @@ -1174,7 +1174,7 @@ string toJSON(const ref JSONValue root, in bool pretty = false, in JSONOptions o // @@@BUG@@@ 14439 // auto names = obj.keys; // aa.keys can't be called in @safe code auto names = new string[obj.length]; - size_t i = 0; + size_t i; foreach (k, v; obj) { names[i] = k; diff --git a/std/math.d b/std/math.d index 6dfd5143740..77cb01bcdfa 100644 --- a/std/math.d +++ b/std/math.d @@ -421,7 +421,7 @@ T floorImpl(T)(const T x) @trusted pure nothrow @nogc int exp = ((y.vu[F.EXPPOS_SHORT] >> 7) & 0xff) - 0x7f; version (LittleEndian) - int pos = 0; + int pos; else int pos = 3; } @@ -430,7 +430,7 @@ T floorImpl(T)(const T x) @trusted pure nothrow @nogc int exp = ((y.vu[F.EXPPOS_SHORT] >> 4) & 0x7ff) - 0x3ff; version (LittleEndian) - int pos = 0; + int pos; else int pos = 3; } @@ -439,7 +439,7 @@ T floorImpl(T)(const T x) @trusted pure nothrow @nogc int exp = (y.vu[F.EXPPOS_SHORT] & 0x7fff) - 0x3fff; version (LittleEndian) - int pos = 0; + int pos; else int pos = 4; } @@ -448,7 +448,7 @@ T floorImpl(T)(const T x) @trusted pure nothrow @nogc int exp = (y.vu[F.EXPPOS_SHORT] & 0x7fff) - 0x3fff; version (LittleEndian) - int pos = 0; + int pos; else int pos = 7; } @@ -915,7 +915,7 @@ Lret: {} return real.nan; // Make argument positive but save the sign. - bool sign = false; + bool sign; if (signbit(x)) { sign = true; @@ -1142,7 +1142,7 @@ real atan(real x) @safe pure nothrow @nogc return copysign(PI_2, x); // Make argument positive but save the sign. - bool sign = false; + bool sign; if (signbit(x)) { sign = true; @@ -3878,7 +3878,7 @@ real hypot(real x, real y) @safe pure nothrow @nogc [ real.nan, real.max, real.nan], [ real.max, real.nan, real.nan], ]; - for (int i = 0; i < vals.length; i++) + for (int i; i < vals.length; i++) { real x = vals[i][0]; real y = vals[i][1]; @@ -5104,7 +5104,7 @@ public: private: ControlState savedState; - bool initialized = false; + bool initialized; version(ARM) { diff --git a/std/net/curl.d b/std/net/curl.d index 6740ecfd86b..55c80cedec3 100644 --- a/std/net/curl.d +++ b/std/net/curl.d @@ -2251,7 +2251,7 @@ decodeString(Char = char)(const(ubyte)[] data, { Char[] res; immutable startLen = data.length; - size_t charsDecoded = 0; + size_t charsDecoded; while (data.length && charsDecoded < maxChars) { immutable dchar dc = scheme.safeDecode(data); @@ -2514,7 +2514,7 @@ struct HTTP copy.initialize(); copy.p.method = p.method; curl_slist* cur = p.headersOut; - curl_slist* newlist = null; + curl_slist* newlist; while (cur) { newlist = Curl.curl.slist_append(newlist, cur.data); @@ -3345,7 +3345,7 @@ struct FTP copy.p.encoding = p.encoding; copy.p.curl = p.curl.dup(); curl_slist* cur = p.commands; - curl_slist* newlist = null; + curl_slist* newlist; while (cur) { newlist = Curl.curl.slist_append(newlist, cur.data); @@ -3994,7 +3994,7 @@ struct SMTP void mailTo()(const(char)[][] recipients...) { assert(!recipients.empty, "Recipient must not be empty"); - curl_slist* recipients_list = null; + curl_slist* recipients_list; foreach (recipient; recipients) { recipients_list = @@ -4972,7 +4972,7 @@ private static void _spawnAsync(Conn, Unit, Terminator = void)() // Number of bytes filled into active buffer Unit[] buffer; - bool aborted = false; + bool aborted; EncodingScheme encodingScheme; static if ( !is(Terminator == void)) diff --git a/std/numeric.d b/std/numeric.d index da287290f68..dffc88f2e23 100644 --- a/std/numeric.d +++ b/std/numeric.d @@ -877,7 +877,7 @@ body T a, b, d; // [a .. b] is our current bracket. d is the third best guess. R fa, fb, fd; // Values of f at a, b, d. - bool done = false; // Has a root been found? + bool done; // Has a root been found? // Allow ax and bx to be provided in reverse order if (ax <= bx) @@ -1178,7 +1178,7 @@ T findRoot(T, R)(scope R delegate(T) f, in T a, in T b, @safe nothrow unittest { - int numProblems = 0; + int numProblems; int numCalls; void testFindRoot(real delegate(real) @nogc @safe nothrow pure f , real x1, real x2) @nogc @safe nothrow pure @@ -1224,7 +1224,7 @@ T findRoot(T, R)(scope R delegate(T) f, in T a, in T b, int n; real ale_a, ale_b; - int powercalls = 0; + int powercalls; real power(real x) { @@ -1850,7 +1850,7 @@ if (isForwardRange!(R)) } else { - uint length = 0; + uint length; foreach (e; range) { s += e; @@ -1878,7 +1878,7 @@ if (isForwardRange!(R)) /// @safe unittest { - double[] a = []; + double[] a; assert(!normalize(a)); a = [ 1.0, 3.0 ]; assert(normalize(a)); @@ -1895,7 +1895,7 @@ The error of this method is much smaller than with a naive sum of log2. ElementType!Range sumOfLog2s(Range)(Range r) if (isInputRange!Range && isFloatingPoint!(ElementType!Range)) { - long exp = 0; + long exp; Unqual!(typeof(return)) x = 1; foreach (e; r) { @@ -2209,7 +2209,7 @@ if (isRandomAccessRange!(R1) && hasLength!(R1) && foreach (i; 0 .. s.length) { const si = s[i]; - for (size_t j = 0;;) + for (size_t j;;) { F dpsij = void; if (binaryFun!(comp)(si, t[j])) @@ -2341,7 +2341,7 @@ time and computes all matches of length 1. this.lambda2 = lambda * lambda; // for efficiency only size_t iMin = size_t.max, jMin = size_t.max, - iMax = 0, jMax = 0; + iMax, jMax; /* initialize */ Tuple!(size_t, size_t) * k0; size_t k0len; @@ -2423,7 +2423,7 @@ time and computes all matches of length 1. F Sij_1 = 0; F Si_1j_1 = 0; auto kli = kl + i * t.length; - for (size_t j = 0;;) + for (size_t j;;) { const klij = kli[j]; const Si_1j = Si[j]; @@ -2686,7 +2686,7 @@ T gcd(T)(T a, T b) static if (canUseBinaryGcd) { - uint shift = 0; + uint shift; while ((a & 1) == 0 && (b & 1) == 0) { a >>= 1; @@ -2952,7 +2952,7 @@ private: // This loop is unrolled and the two iterations are interleaved // relative to the textbook FFT to increase ILP. This gives roughly 5% // speedups on DMD. - for (size_t k = 0; k < halfLen; k += 2) + for (size_t k; k < halfLen; k += 2) { immutable cosTwiddle1 = cosFromLookup(k); immutable sinTwiddle1 = negSinFromLookup(k); diff --git a/std/parallelism.d b/std/parallelism.d index 51d322172d0..a9953d87baf 100644 --- a/std/parallelism.d +++ b/std/parallelism.d @@ -167,7 +167,7 @@ immutable size_t cacheLineSize; shared static this() { import core.cpuid : datacache; - size_t lineSize = 0; + size_t lineSize; foreach (cachelevel; datacache) { if (cachelevel.lineSize > lineSize && cachelevel.lineSize < uint.max) @@ -1700,7 +1700,7 @@ public: // Handle as a special case: if (size == 0) { - size_t index = 0; + size_t index; foreach (elem; range) { emplaceRef(buf[index++], fun(elem)); @@ -2008,7 +2008,7 @@ public: // Handle as a special case: if (pool.size == 0) { - size_t index = 0; + size_t index; foreach (elem; toMap) { buf[index++] = fun(elem); @@ -2662,7 +2662,7 @@ public: return tmp; } - size_t curPos = 0; + size_t curPos; void useTask(ref RTask task) { import std.algorithm.comparison : min; @@ -3483,8 +3483,8 @@ int doSizeZeroCase(R, Delegate)(ref ParallelForeach!R p, Delegate dg) { with(p) { - int res = 0; - size_t index = 0; + int res; + size_t index; // The explicit ElementType!R in the foreach loops is necessary for // correct behavior when iterating over strings. @@ -3992,7 +3992,7 @@ version(unittest) assert(ct.args[0] == 1); // Test ref return. - uint toInc = 0; + uint toInc; static ref T makeRef(T)(ref T num) { return num; @@ -4384,7 +4384,7 @@ version(parallelismStressTest) auto sumFuture = task!( reduce!"a + b" )(numbers); poolInstance.put(sumFuture); - ulong sumSquares = 0; + ulong sumSquares; foreach (elem; numbers) { sumSquares += elem * elem; diff --git a/std/path.d b/std/path.d index a9f0bd8015d..d09839f36ae 100644 --- a/std/path.d +++ b/std/path.d @@ -244,7 +244,7 @@ if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementType!R) || { static if (isRandomAccessRange!R && hasSlicing!R || isNarrowString!R) { - int i = 0; + int i; while (i < path.length && isDirSeparator(path[i])) ++i; return path[i .. path.length]; @@ -1358,14 +1358,14 @@ immutable(ElementEncodingType!(ElementType!Range))[] static if (isForwardRange!Range) { auto segments2 = segments.save; - size_t precalc = 0; + size_t precalc; foreach (segment; segments2) precalc += segment.length + 1; } // Otherwise, just venture a guess and resize later if necessary. else size_t precalc = 255; auto buf = new Unqual!(ElementEncodingType!(ElementType!Range))[](precalc); - size_t pos = 0; + size_t pos; foreach (segment; segments) { if (segment.empty) continue; @@ -1544,7 +1544,7 @@ if ((isRandomAccessRange!R1 && hasSlicing!R1 && hasLength!R1 && isSomeChar!(Elem alias CR = Unqual!(ElementEncodingType!R1); auto sep = only(CR(dirSeparator[0])); - bool usesep = false; + bool usesep; auto pos = r1.length; @@ -3740,7 +3740,7 @@ if ((isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && isSomeC // Check that each component satisfies isValidComponent. while (!remainder.empty) { - size_t i = 0; + size_t i; while (i < remainder.length && !isDirSeparator(remainder[i])) ++i; assert(i > 0); if (!isValidComponent(remainder[0 .. i])) return false; diff --git a/std/process.d b/std/process.d index 93627da1e13..834b3196fb2 100644 --- a/std/process.d +++ b/std/process.d @@ -703,7 +703,7 @@ private const(char*)* createEnv(const string[string] childEnv, bool mergeWithParentEnv) { // Determine the number of strings in the parent's environment. - int parentEnvLength = 0; + int parentEnvLength; auto environ = getEnvironPtr; if (mergeWithParentEnv) { @@ -713,14 +713,14 @@ private const(char*)* createEnv(const string[string] childEnv, // Convert the "new" variables to C-style strings. auto envz = new const(char)*[parentEnvLength + childEnv.length + 1]; - int pos = 0; + int pos; foreach (var, val; childEnv) envz[pos++] = (var~'='~val~'\0').ptr; // Add the parent's environment. foreach (environStr; environ[0 .. parentEnvLength]) { - int eqPos = 0; + int eqPos; while (environStr[eqPos] != '=' && environStr[eqPos] != '\0') ++eqPos; if (environStr[eqPos] != '=') continue; auto var = environStr[0 .. eqPos]; @@ -738,7 +738,7 @@ version (Posix) @system unittest auto e2 = createEnv(null, true); assert(e2 != null); - int i = 0; + int i; auto environ = getEnvironPtr; for (; environ[i] != null; ++i) { @@ -1100,8 +1100,8 @@ version (Posix) @system unittest { TestScript prog = ""; - string directory = ""; - assert(directory.ptr && !directory.length); + string directory; + assert(!directory.length); spawnProcess([prog.path], null, Config.none, directory).wait(); } @@ -2844,7 +2844,7 @@ if (is(typeof(allocator(size_t.init)[0] = char.init))) // Trailing backslashes must be escaped bool escaping = true; - bool needEscape = false; + bool needEscape; // Result size = input size + 2 for surrounding quotes + 1 for the // backslash for each escaped character. size_t size = 1 + arg.length + 1; @@ -2980,7 +2980,7 @@ if (is(typeof(allocator(size_t.init)[0] = char.init))) size += 3; auto buf = allocator(size); - size_t p = 0; + size_t p; buf[p++] = '\''; foreach (char c; arg) if (c == '\'') @@ -3337,7 +3337,7 @@ static: version (Posix) { auto environ = getEnvironPtr; - for (int i=0; environ[i] != null; ++i) + for (int i; environ[i] != null; ++i) { import std.string : indexOf; @@ -3364,7 +3364,7 @@ static: enforce(envBlock, "Failed to retrieve environment variables."); scope(exit) FreeEnvironmentStringsW(envBlock); - for (int i=0; envBlock[i] != '\0'; ++i) + for (int i; envBlock[i] != '\0'; ++i) { auto start = i; while (envBlock[i] != '=') ++i; @@ -3776,9 +3776,8 @@ version(Posix) else { // No, so must traverse PATHs, looking for first match - string[] envPaths = split( - to!string(core.stdc.stdlib.getenv("PATH")), ":"); - int iRet = 0; + string[] envPaths = split(to!string(core.stdc.stdlib.getenv("PATH")), ":"); + int iRet; // Note: if any call to execve() succeeds, this process will cease // execution, so there's no need to check the execve() result through diff --git a/std/random.d b/std/random.d index 7fcda195312..5cc22663b71 100644 --- a/std/random.d +++ b/std/random.d @@ -1411,7 +1411,7 @@ if (!is(CommonType!(T1, T2) == void)) foreach (i; 0 .. 20) { - immutable ubyte a = 0; + immutable ubyte a; immutable ubyte b = 15; auto x = uniform(a, b, gen); assert(a <= x && x < b); @@ -1659,7 +1659,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) && } { - bool sawLB = false, sawUB = false; + bool sawLB, sawUB; foreach (i; 0 .. 50) { auto x = uniform!"[]"('a', 'd', reproRng); @@ -1671,7 +1671,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) && } { - bool sawLB = false, sawUB = false; + bool sawLB, sawUB; foreach (i; 0 .. 50) { auto x = uniform('a', 'd', reproRng); @@ -1683,7 +1683,7 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) && } { - bool sawLB = false, sawUB = false; + bool sawLB, sawUB; foreach (i; 0 .. 50) { immutable int lo = -2, hi = 2; @@ -1696,10 +1696,10 @@ if ((isIntegral!(CommonType!(T1, T2)) || isSomeChar!(CommonType!(T1, T2))) && } { - bool sawLB = false, sawUB = false; + bool sawLB, sawUB; foreach (i; 0 .. 50) { - immutable ubyte lo = 0, hi = 5; + immutable ubyte lo, hi = 5; auto x = uniform(lo, hi, reproRng); if (x == lo) sawLB = true; if (x == (hi-1)) sawUB = true; @@ -2251,7 +2251,7 @@ body assert(point < sum); auto mass = 0.0; - size_t i = 0; + size_t i; foreach (e; proportions) { mass += e; @@ -2331,8 +2331,8 @@ if (isRandomAccessRange!Range && (isUniformRNG!UniformRNG || is(UniformRNG == vo private Range _input; private bool[] _chosen; private size_t _current; - private size_t _alreadyChosen = 0; - private bool _isEmpty = false; + private size_t _alreadyChosen; + private bool _isEmpty; static if (is(UniformRNG == void)) { @@ -2496,7 +2496,7 @@ if (isRandomAccessRange!Range) @safe unittest { // Bugzilla 12589 - int[] r = []; + int[] r; auto rc = randomCover(r); assert(rc.length == 0); assert(rc.empty); @@ -3112,7 +3112,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG) * correctly. */ { - uint i = 0; + uint i; foreach (e; randomSample(a, a.length)) { assert(e == i); @@ -3156,7 +3156,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG) */ { // Small sample/source ratio, no specified RNG. - uint i = 0; + uint i; foreach (e; randomSample(randomCover(a), 5)) { ++i; @@ -3290,7 +3290,7 @@ if (isInputRange!Range && hasLength!Range && isUniformRNG!UniformRNG) static assert(!isForwardRange!(typeof(sample1))); assert(sample1.length == 789); assert(sample1._available == 456_789); - uint i = 0; + uint i; for (; !sample1.empty; sample1.popFront()) { assert(sample1.front == sample1.index); diff --git a/std/range/interfaces.d b/std/range/interfaces.d index 76d00e38ff8..4ebf0ec238d 100644 --- a/std/range/interfaces.d +++ b/std/range/interfaces.d @@ -466,7 +466,7 @@ if (isInputRange!(Unqual!R)) int opApply(scope int delegate(size_t, E) dg) { int res; - size_t i = 0; + size_t i; for (auto r = _range; !r.empty; r.popFront()) { res = dg(i, r.front); diff --git a/std/range/package.d b/std/range/package.d index 589cf127ce2..69feb51098d 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -704,7 +704,7 @@ pure @safe nothrow @nogc unittest debug pure nothrow @system unittest {//check the contract int[4] testArr = [1,2,3,4]; - bool passed = false; + bool passed; scope (success) assert(passed); import core.exception : AssertError; //std.exception.assertThrown won't do because it can't infer nothrow @@ -4308,7 +4308,7 @@ pure @safe unittest assert(result == [ "1a", "2b", "3c" ]); - size_t idx = 0; + size_t idx; // unpacking tuple elements with foreach foreach (e1, e2; zip(a, b)) { @@ -5773,12 +5773,12 @@ debug @system unittest unittest { { - ushort start = 0, end = 10, step = 2; + ushort start, end = 10, step = 2; foreach (i; iota(start, end, step)) static assert(is(typeof(i) == ushort)); } { - ubyte start = 0, end = 255, step = 128; + ubyte start, end = 255, step = 128; uint x; foreach (i; iota(start, end, step)) { @@ -6576,7 +6576,7 @@ private: @safe unittest { // Boundary case: transpose of empty range should be empty - int[][] ror = []; + int[][] ror; assert(transposed(ror).empty); } @@ -7406,7 +7406,7 @@ if (isForwardRange!Source && hasLength!Source) { import std.algorithm.comparison : equal; - int[] source = []; + int[] source; auto chunks = source.evenChunks(0); assert(chunks.length == 0); chunks = source.evenChunks(3); @@ -8467,8 +8467,8 @@ private struct OnlyResult(T, size_t arity) return result; } - private size_t frontIndex = 0; - private size_t backIndex = 0; + private size_t frontIndex; + private size_t backIndex; // @@@BUG@@@ 10643 version(none) @@ -8663,7 +8663,7 @@ if (!is(CommonType!Values == void) || Values.length == 0) foreach (x; tuple(1, '1', 1.0, "1", [1])) { auto a = only(x); - typeof(x)[] e = []; + typeof(x)[] e; assert(a.front == x); assert(a.back == x); assert(!a.empty); @@ -8691,7 +8691,7 @@ if (!is(CommonType!Values == void) || Values.length == 0) } auto imm = only!(immutable int)(1); - immutable int[] imme = []; + immutable int[] imme; assert(imm.front == 1); assert(imm.back == 1); assert(!imm.empty); @@ -9044,7 +9044,7 @@ pure @safe nothrow unittest saved.popFront(); assert(saved.empty); - size_t control = 0; + size_t control; foreach (i, v; enumerated) { static assert(is(typeof(i) == size_t)); @@ -9394,7 +9394,7 @@ if (isInputRange!Range) private size_t getTransitionIndex(SearchPolicy sp, alias test, V)(V v) if (sp == SearchPolicy.binarySearch && isRandomAccessRange!Range && hasLength!Range) { - size_t first = 0, count = _input.length; + size_t first, count = _input.length; while (count > 0) { immutable step = count / 2, it = first + step; @@ -9419,7 +9419,7 @@ if (isInputRange!Range) if (empty || test(front, v)) return 0; immutable count = length; if (count == 1) return 1; - size_t below = 0, above = 1, step = 2; + size_t below, above = 1, step = 2; while (!test(_input[above], v)) { // Still too small, update below and increase gait @@ -9565,7 +9565,7 @@ See_Also: STL's $(HTTP sgi.com/tech/stl/lower_bound.html,upper_bound). if (isTwoWayCompatible!(predFun, ElementType!Range, V) && isRandomAccessRange!Range) { - size_t first = 0, count = _input.length; + size_t first, count = _input.length; while (count > 0) { immutable step = count / 2; @@ -9623,7 +9623,7 @@ equalRange). Completes the entire search in $(BIGOH log(n)) time. && isRandomAccessRange!Range && hasLength!Range) { import std.typecons : tuple; - size_t first = 0, count = _input.length; + size_t first, count = _input.length; while (count > 0) { immutable step = count / 2; @@ -10675,7 +10675,7 @@ private: { @property int front() {return 0;} void popFront() {empty = true;} - bool empty = false; + bool empty; } R r; refRange(&r).popFront(); @@ -10688,7 +10688,7 @@ private: { Object front; alias back = front; - bool empty = false; + bool empty; void popFront() {empty = true;} alias popBack = popFront; @property R save() {return this;} @@ -10702,7 +10702,7 @@ private: @property Object front() {return null;} @property const(Object) front() const {return null;} alias back = front; - bool empty = false; + bool empty; void popFront() {empty = true;} alias popBack = popFront; @property R2 save() {return this;} @@ -11374,13 +11374,13 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) // Sum values while copying int[] values = [1, 4, 9, 16, 25]; - int sum = 0; + int sum ; auto newValues = values.tee!(a => sum += a).array; assert(equal(newValues, values)); assert(sum == 1 + 4 + 9 + 16 + 25); // Count values that pass the first filter - int count = 0; + int count; auto newValues4 = values.filter!(a => a < 10) .tee!(a => count++) .map!(a => a + 1) @@ -11400,7 +11400,7 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) int[] values = [1, 4, 9, 16, 25]; - int count = 0; + int count; auto newValues = values.filter!(a => a < 10) .tee!(a => count++, No.pipeOnPop) .map!(a => a + 1) @@ -11418,7 +11418,7 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) newValues.front; assert(count == 2); - int[] preMap = new int[](3), postMap = []; + int[] preMap = new int[](3), postMap; auto mappedValues = values.filter!(a => a < 10) //Note the two different ways of using tee .tee(preMap) @@ -11444,8 +11444,8 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) return "AaEeIiOoUu".indexOf(c) != -1; } - int vowelCount = 0; - int shiftedCount = 0; + int vowelCount; + int shiftedCount; auto removeVowels = txt.tee!(c => isVowel(c) ? vowelCount++ : 0) .filter!(c => !isVowel(c)) .map!(c => (c == ' ') ? c : c + 1) @@ -11461,7 +11461,7 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) void testRange(Range)(Range r) { const int strideLen = 3; - int i = 0; + int i; ElementType!Range elem1; ElementType!Range elem2; while (!r.empty) @@ -11481,12 +11481,12 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) string txt = "abcdefghijklmnopqrstuvwxyz"; - int popCount = 0; + int popCount; auto pipeOnPop = txt.tee!(a => popCount++); testRange(pipeOnPop); assert(popCount == 26); - int frontCount = 0; + int frontCount; auto pipeOnFront = txt.tee!(a => frontCount++, No.pipeOnPop); testRange(pipeOnFront); assert(frontCount == 9); @@ -11500,17 +11500,17 @@ if (is(typeof(fun) == void) || isSomeFunction!fun) //Test diverting elements to an OutputRange string txt = "abcdefghijklmnopqrstuvwxyz"; - dchar[] asink1 = []; + dchar[] asink1; auto fsink = (dchar c) { asink1 ~= c; }; auto result1 = txt.tee(fsink).array; assert(equal(txt, result1) && (equal(result1, asink1))); - dchar[] _asink1 = []; + dchar[] _asink1; auto _result1 = txt.tee!((dchar c) { _asink1 ~= c; })().array; assert(equal(txt, _result1) && (equal(_result1, _asink1))); dchar[] asink2 = new dchar[](txt.length); - void fsink2(dchar c) { static int i = 0; asink2[i] = c; i++; } + void fsink2(dchar c) { static int i; asink2[i] = c; i++; } auto result2 = txt.tee(&fsink2).array; assert(equal(txt, result2) && equal(result2, asink2)); diff --git a/std/range/primitives.d b/std/range/primitives.d index 7dc0d018a02..9d4bbd538c0 100644 --- a/std/range/primitives.d +++ b/std/range/primitives.d @@ -518,7 +518,7 @@ pure @safe unittest } struct RetroResult { - bool end = false; + bool end; @property bool empty() const { return end; } @property dchar front(){ return 'a'; } void popFront(){ end = true; } @@ -2331,7 +2331,7 @@ if (isNarrowString!(T[])) { import std.utf : decode; assert(a.length, "Attempting to fetch the front of an empty array of " ~ T.stringof); - size_t i = 0; + size_t i; return decode(a, i); } diff --git a/std/regex/internal/backtracking.d b/std/regex/internal/backtracking.d index ffc9779923a..1d464b060db 100644 --- a/std/regex/internal/backtracking.d +++ b/std/regex/internal/backtracking.d @@ -1192,7 +1192,7 @@ struct CtContext string ctQuickTest(Bytecode[] ir, int id) { - uint pc = 0; + uint pc; while (pc < ir.length && ir[pc].isAtom) { if (ir[pc].code == IR.GroupStart || ir[pc].code == IR.GroupEnd) @@ -1251,7 +1251,7 @@ struct CtContext if (atEnd) $$`, bailOut); immutable len = ir[0].sequence; - for (uint i = 0; i < len; i++) + for (uint i; i < len; i++) { code ~= ctSub( ` if (front == $$) diff --git a/std/regex/internal/generator.d b/std/regex/internal/generator.d index 6831e59ed2e..e174985fbb6 100644 --- a/std/regex/internal/generator.d +++ b/std/regex/internal/generator.d @@ -41,7 +41,7 @@ module std.regex.internal.generator; void compose() { - uint pc = 0, counter = 0, dataLenOld = uint.max; + uint pc, counter, dataLenOld = uint.max; for (;;) { switch (re.ir[pc].code) @@ -84,7 +84,7 @@ module std.regex.internal.generator; goto case; case IR.Option: uint next = pc + re.ir[pc].data + IRL!(IR.Option); - uint nOpt = 0; + uint nOpt; //queue next Option while (re.ir[next].code == IR.Option) { diff --git a/std/regex/internal/ir.d b/std/regex/internal/ir.d index 28b199895d9..7f2a2a2343f 100644 --- a/std/regex/internal/ir.d +++ b/std/regex/internal/ir.d @@ -448,7 +448,7 @@ struct Group(DataIndex) @trusted void printBytecode()(in Bytecode[] slice, in NamedGroup[] dict=[]) { import std.stdio : writeln; - for (uint pc=0; pc= maxDigit,"incomplete escape sequence"); uint val; - for (int k = 0; k < maxDigit; k++) + for (int k; k < maxDigit; k++) { immutable current = str[k];//accepts ascii only, so it's OK to index directly if ('0' <= current && current <= '9') @@ -255,9 +255,9 @@ struct CodeGen Stack!(uint) fixupStack; // stack of opened start instructions NamedGroup[] dict; // maps name -> user group number Stack!(uint) groupStack; // stack of current number of group - uint nesting = 0; // group nesting level and repetitions step - uint lookaroundNest = 0; // nesting of lookaround - uint counterDepth = 0; // current depth of nested counted repetitions + uint nesting; // group nesting level and repetitions step + uint lookaroundNest; // nesting of lookaround + uint counterDepth; // current depth of nested counted repetitions CodepointSet[] charsets; // sets for char classes const(CharMatcher)[] matchers; // matchers for char classes uint[] backrefed; // bitarray for groups refered by backref @@ -619,7 +619,7 @@ if (isForwardRange!R && is(ElementType!R : dchar)) dchar _current; bool empty; R pat, origin; //keep full pattern for pretty printing error messages - uint re_flags = 0; //global flags e.g. multiline + internal ones + uint re_flags; //global flags e.g. multiline + internal ones Generator g; @trusted this(S)(R pattern, S flags) @@ -676,7 +676,7 @@ if (isForwardRange!R && is(ElementType!R : dchar)) //parsing number with basic overflow check uint parseDecimal() { - uint r = 0; + uint r ; while (std.ascii.isDigit(current)) { if (r >= (uint.max/10)) @@ -1500,7 +1500,7 @@ if (isForwardRange!R && is(ElementType!R : dchar)) { enum MAX_PROPERTY = 128; char[MAX_PROPERTY] result; - uint k = 0; + uint k; enforce(next(), "eof parsing unicode property spec"); if (current == '{') { @@ -1560,8 +1560,8 @@ if (isForwardRange!R && is(ElementType!R : dchar)) } auto counterRange = FixedStack!uint(new uint[maxCounterDepth+1], -1); counterRange.push(1); - ulong cumRange = 0; - for (uint i = 0; i < ir.length; i += ir[i].length) + ulong cumRange; + for (uint i; i < ir.length; i += ir[i].length) { if (ir[i].hotspot) { @@ -1616,7 +1616,7 @@ void fixupBytecode()(Bytecode[] ir) { Stack!uint fixups; - with(IR) for (uint i=0; i[a-zA-Z0-9_]+):*(?P[a-zA-Z0-9_]*)","gm"); auto uniCapturesNew = match(uniFileOld, r); - for (int i = 0; i < 20; i++) + for (int i; i < 20; i++) foreach (matchNew; uniCapturesNew) {} //a second issue with same symptoms auto r2 = regex(`([а-яА-Я\-_]+\s*)+(?<=[\s\.,\^])`); diff --git a/std/regex/internal/thompson.d b/std/regex/internal/thompson.d index 4d7deaa1f88..1fdd24aab82 100644 --- a/std/regex/internal/thompson.d +++ b/std/regex/internal/thompson.d @@ -26,7 +26,7 @@ struct Thread(DataIndex) //head-tail singly-linked list struct ThreadList(DataIndex) { - Thread!DataIndex* tip = null, toe = null; + Thread!DataIndex* tip, toe; //add new thread to the start of list void insertFront(Thread!DataIndex* t) { @@ -822,7 +822,7 @@ if (is(Char : dchar)) opCacheBackTrue = arrayInChunk!(OpBackFunc)(re.ir.length, memory); opCacheBackFalse = arrayInChunk!(OpBackFunc)(re.ir.length, memory); - for (uint pc = 0; pc= ST.inemitting); if (status == ST.inemitting_disconnected) { - for (size_t j = 0; j < slots_idx;) + for (size_t j; j < slots_idx;) { if (slots[j] is null) { @@ -179,8 +179,8 @@ mixin template Signal(T1...) final void disconnect(slot_t slot) { debug (signal) writefln("Signal.disconnect(slot)"); - size_t disconnectedSlots = 0; - size_t instancePreviousSlots = 0; + size_t disconnectedSlots; + size_t instancePreviousSlots; if (status >= ST.inemitting) { foreach (i, sloti; slots[0 .. slots_idx]) @@ -197,7 +197,7 @@ mixin template Signal(T1...) } else { - for (size_t i = 0; i < slots_idx; ) + for (size_t i; i < slots_idx; ) { if (slots[i].ptr == slot.ptr && ++instancePreviousSlots && @@ -230,7 +230,7 @@ mixin template Signal(T1...) in { assert( status == ST.idle ); } body { debug (signal) writefln("Signal.unhook(o = %s)", cast(void*) o); - for (size_t i = 0; i < slots_idx; ) + for (size_t i; i < slots_idx; ) { if (_d_toObject(slots[i].ptr) is o) { slots_idx--; @@ -279,7 +279,7 @@ mixin template Signal(T1...) { import std.signals; - int observedMessageCounter = 0; + int observedMessageCounter; class Observer { // our slot diff --git a/std/socket.d b/std/socket.d index a375e2ee058..1d4f34c0aef 100644 --- a/std/socket.d +++ b/std/socket.d @@ -932,7 +932,7 @@ private string formatGaiError(int err) @trusted */ AddressInfo[] getAddressInfo(T...)(in char[] node, T options) { - const(char)[] service = null; + const(char)[] service; addrinfo hints; hints.ai_family = AF_UNSPEC; @@ -2555,7 +2555,7 @@ private: AddressFamily _family; version(Windows) - bool _blocking = false; /// Property to get or set whether the socket is blocking or nonblocking. + bool _blocking; /// Property to get or set whether the socket is blocking or nonblocking. // The WinSock timeouts seem to be effectively skewed by a constant // offset of about half a second (value in milliseconds). This has @@ -3345,7 +3345,7 @@ public: body { fd_set* fr, fw, fe; - int n = 0; + int n; version(Windows) { diff --git a/std/stdio.d b/std/stdio.d index 1464445fd7f..c04235b3834 100644 --- a/std/stdio.d +++ b/std/stdio.d @@ -355,7 +355,7 @@ struct File private struct Impl { - FILE * handle = null; // Is null iff this Impl is closed by another File + FILE * handle; // Is null iff this Impl is closed by another File uint refs = uint.max / 2; bool isPopened; // true iff the stream has been created by popen() Orientation orientation; @@ -1551,7 +1551,7 @@ void main() { auto witness = [ "hello\n", "world\n" ]; auto f = File(deleteme); - uint i = 0; + uint i; String buf; while ((buf = f.readln!String()).length) { @@ -1773,7 +1773,7 @@ is recommended if you want to process a complete file. { immutable(C)[][] witness = [ "hello\n\r", "world\nhow\n\r", "are ya" ]; auto f = File(deleteme); - uint i = 0; + uint i; C[] buf; while (f.readln(buf, "\n\r")) { @@ -4127,7 +4127,7 @@ struct lines { enum bool duplicate = is(Parms[$ - 1] == string) || is(Parms[$ - 1] == wstring) || is(Parms[$ - 1] == dstring); - int result = 0; + int result; static if (is(Parms[$ - 1] : const(char)[])) alias C = char; else static if (is(Parms[$ - 1] : const(wchar)[])) @@ -4237,7 +4237,7 @@ struct lines // test looping with a file with three lines std.file.write(deleteme, "Line one\nline two\nline three\n"); f.open(deleteme, "r"); - uint i = 0; + uint i; foreach (T line; lines(f)) { if (i == 0) assert(line == "Line one\n"); @@ -4279,7 +4279,7 @@ struct lines // test looping with a file with three lines std.file.write(deleteme, "Line one\nline two\nline three\n"); f.open(deleteme, "r"); - uint i = 0; + uint i; foreach (T line; lines(f)) { if (i == 0) assert(cast(char[]) line == "Line one\n"); @@ -4313,7 +4313,7 @@ struct lines // using a counter too this time std.file.write(deleteme, "Line one\nline two\nline three"); auto f = File(deleteme, "r"); - uint i = 0; + uint i; foreach (ulong j, T line; lines(f)) { if (i == 0) assert(cast(char[]) line == "Line one\n"); @@ -4380,7 +4380,7 @@ private struct ChunksImpl buffer = new ubyte[size]; size_t r = void; int result = 1; - uint tally = 0; + uint tally; while ((r = trustedFread(f._p.handle, buffer)) > 0) { assert(r <= size); @@ -4425,7 +4425,7 @@ private struct ChunksImpl // test looping with a file with three lines std.file.write(deleteme, "Line one\nline two\nline three\n"); f = File(deleteme, "r"); - uint i = 0; + uint i; foreach (ubyte[] line; chunks(f, 3)) { if (i == 0) assert(cast(char[]) line == "Lin"); @@ -4635,7 +4635,7 @@ private struct ReadlnAppender { char[] buf; size_t pos; - bool safeAppend = false; + bool safeAppend; void initialize(char[] b) { @@ -4930,8 +4930,8 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie } } - static char *lineptr = null; - static size_t n = 0; + static char *lineptr; + static size_t n; scope(exit) { if (n > 128 * 1024) @@ -5032,7 +5032,7 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie // Narrow stream // First, fill the existing buffer - for (size_t bufPos = 0; bufPos < buf.length; ) + for (size_t bufPos; bufPos < buf.length; ) { immutable c = FGETC(fp); if (c == -1) diff --git a/std/string.d b/std/string.d index 2635a78f521..5481547c39a 100644 --- a/std/string.d +++ b/std/string.d @@ -324,7 +324,7 @@ pure nothrow @system unittest p = toStringz(foo[3 .. 5]); assert(strlen(p) == 2); - string test = ""; + string test; p = toStringz(test); assert(*p == 0); @@ -336,7 +336,7 @@ pure nothrow @system unittest p = toStringz(test); assert(p[0] == 'f' && p[1] == 'o' && p[2] == 'o' && p[3] == 0); - const string test2 = ""; + const string test2; p = toStringz(test2); assert(*p == 0); } @@ -749,7 +749,7 @@ if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && /* Classic double nested loop search algorithm */ - ptrdiff_t index = 0; // count code unit index into s + ptrdiff_t index; // count code unit index into s for (auto sbydchar = s.byDchar(); !sbydchar.empty; sbydchar.popFront()) { dchar c2 = sbydchar.front; @@ -1489,7 +1489,7 @@ if (isSomeChar!Char && isSomeChar!Char2) import std.range.primitives : walkLength; if (needles.length <= 16 && needles.walkLength(17)) { - size_t si = 0; + size_t si; dchar[16] scratch = void; foreach ( dchar c; needles) { @@ -2405,7 +2405,7 @@ if (isSomeString!S) import std.array : appender; import std.uni : lineSep, paraSep; - size_t iStart = 0; + size_t iStart; auto retval = appender!(S[])(); for (size_t i; i < s.length; ++i) @@ -3015,7 +3015,7 @@ if (isSomeString!Range || } else { - size_t stride = 0; + size_t stride; while (1) { @@ -5070,7 +5070,7 @@ body foreach (char c; toRemove) remTable[c] = true; - size_t count = 0; + size_t count; foreach (char c; str) { if (!remTable[c]) @@ -5079,7 +5079,7 @@ body auto buffer = new char[count]; - size_t i = 0; + size_t i; foreach (char c; str) { if (!remTable[c]) @@ -5257,8 +5257,8 @@ deprecated("This function is obsolete and will be removed May 2018. See the docs bool inPattern(S)(dchar c, in S pattern) @safe pure @nogc if (isSomeString!S) { - bool result = false; - int range = 0; + bool result; + int range; dchar lastc; foreach (size_t i, dchar p; pattern) @@ -5393,7 +5393,7 @@ if (isSomeString!S) import std.utf : encode; Unqual!(typeof(s[0]))[] r; - bool changed = false; + bool changed; foreach (size_t i, dchar c; s) { @@ -5725,9 +5725,9 @@ C1[] tr(C1, C2, C3, C4 = immutable char) dchar lastf; dchar lastt; dchar newc; - int n = 0; + int n; - for (size_t i = 0; i < from.length; ) + for (size_t i; i < from.length; ) { immutable f = decode(from, i); if (f == '-' && lastf != dchar.init && i < from.length) @@ -5761,7 +5761,7 @@ C1[] tr(C1, C2, C3, C4 = immutable char) // Find the nth character in to[] dchar nextt; - for (size_t i = 0; i < to.length; ) + for (size_t i; i < to.length; ) { immutable t = decode(to, i); if (t == '-' && lastt != dchar.init && i < to.length) @@ -5925,7 +5925,7 @@ if (isSomeString!S || immutable iLen = codeUnits.length; bool bDecimalPoint, bExponent, bComplex, sawDigits; - for (size_t i = 0; i < iLen; i++) + for (size_t i; i < iLen; i++) { immutable c = codeUnits[i]; @@ -6221,7 +6221,7 @@ if (isInputRange!Range && isSomeChar!(ElementEncodingType!Range) && "01230120022455012623010202"; char[4] result = void; - size_t b = 0; + size_t b; C lastc; foreach (C c; str) { @@ -6401,7 +6401,7 @@ string[string] abbrev(string[] values) @safe pure string nv; string lv; - for (size_t i = 0; i < values_length; i = nexti) + for (size_t i; i < values_length; i = nexti) { string value = values[i]; @@ -6415,7 +6415,7 @@ string[string] abbrev(string[] values) @safe pure import std.utf : stride; - for (size_t j = 0; j < value.length; j += stride(value, j)) + for (size_t j; j < value.length; j += stride(value, j)) { string v = value[0 .. j]; diff --git a/std/traits.d b/std/traits.d index e53fc8f7616..ec1bd3dd3b6 100644 --- a/std/traits.d +++ b/std/traits.d @@ -184,7 +184,7 @@ private /* Demangles mstr as the storage class part of Argument. */ Demangle!uint demangleParameterStorageClass(string mstr) { - uint pstc = 0; // parameter storage class + uint pstc; // parameter storage class // Argument --> Argument2 | M Argument2 if (mstr.length > 0 && mstr[0] == 'M') @@ -232,7 +232,7 @@ private 'j': FunctionAttribute.return_, 'l': FunctionAttribute.scope_ ]; - uint atts = 0; + uint atts; // FuncAttrs --> FuncAttr | FuncAttr FuncAttrs // FuncAttr --> empty | Na | Nb | Nc | Nd | Ne | Nf | Ni | Nj @@ -3616,8 +3616,8 @@ template hasStaticMember(T, string member) struct S {} class C {} - static int sx = 0; - __gshared int gx = 0; + static int sx; + __gshared int gx; Y y; static Y sy; @@ -3654,8 +3654,8 @@ template hasStaticMember(T, string member) struct S {} class C {} - static int sx = 0; - __gshared int gx = 0; + static int sx; + __gshared int gx; Y y; static Y sy; @@ -4659,7 +4659,7 @@ package template isBlitAssignable(T) { enum isBlitAssignable = isMutable!T && { - size_t offset = 0; + size_t offset; bool assignable = true; foreach (i, F; FieldTypeTuple!T) { diff --git a/std/typecons.d b/std/typecons.d index 6671f5e9d46..0a5196ad543 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -233,7 +233,7 @@ private: @system unittest { // test conversion to base ref - int deleted = 0; + int deleted; class C { ~this(){deleted++;} @@ -413,7 +413,7 @@ template Tuple(Specs...) // variable) and can't be aliased directly. string injectNamedFields() { - string decl = ""; + string decl; foreach (i, name; staticMap!(extractName, fieldSpecs)) { import std.format : format; @@ -1016,7 +1016,7 @@ template Tuple(Specs...) */ size_t toHash() const nothrow @trusted { - size_t h = 0; + size_t h; foreach (i, T; Types) h += typeid(T).getHash(cast(const void*)&field[i]); return h; @@ -4114,7 +4114,7 @@ private static: */ public string generateCode(overloads...)() @property { - string code = ""; + string code; // run through all the overload sets foreach (i_; CountUp!(0 + overloads.length)) // workaround @@ -4141,7 +4141,7 @@ private static: // handle each overload set private string generateCodeForOverloadSet(alias oset)() @property { - string code = ""; + string code; foreach (i_; CountUp!(0 + oset.contents.length)) // workaround { @@ -4184,7 +4184,7 @@ private static: // return type with optional "ref" static string make_returnType() { - string rtype = ""; + string rtype; if (!isCtor) { @@ -4198,7 +4198,7 @@ private static: // function attributes attached after declaration static string make_postAtts() { - string poatts = ""; + string poatts; if (atts & FA.pure_ ) poatts ~= " pure"; if (atts & FA.nothrow_) poatts ~= " nothrow"; if (atts & FA.property) poatts ~= " @property"; @@ -4211,7 +4211,7 @@ private static: // function storage class static string make_storageClass() { - string postc = ""; + string postc; if (is(Func == shared)) postc ~= " shared"; if (is(Func == const)) postc ~= " const"; if (is(Func == inout)) postc ~= " inout"; @@ -4273,8 +4273,8 @@ private static: alias stcs = ParameterStorageClassTuple!(func); enum nparams = stcs.length; - string imports = ""; // any imports required - string params = ""; // parameters + string imports; // any imports required + string params; // parameters foreach (i, stc; stcs) { @@ -4318,7 +4318,7 @@ private static: // separator. "a0, a1, a2, a3" private string enumerateParameters(size_t n)() @property { - string params = ""; + string params; foreach (i_; CountUp!(n)) { diff --git a/std/uni.d b/std/uni.d index 40c4799c1d7..80d5f9f073e 100644 --- a/std/uni.d +++ b/std/uni.d @@ -758,7 +758,7 @@ void copyBackwards(T,U)(T[] src, U[] dest) void copyForward(T,U)(T[] src, U[] dest) { assert(src.length == dest.length); - for (size_t i=0; i= max) { @@ -2119,7 +2119,7 @@ public: { import std.conv : text; assert(intervals.length % 2 == 0, "Odd number of interval bounds [a, b)!"); - for (uint i = 0; i < intervals.length; i += 2) + for (uint i; i < intervals.length; i += 2) { auto a = intervals[i], b = intervals[i+1]; assert(a < b, text("illegal interval [a, b): ", a, " > ", b)); @@ -2140,7 +2140,7 @@ public: { import std.conv : text; assert(intervals.length % 2 == 0, "Odd number of interval bounds [a, b)!"); - for (uint i = 0; i < intervals.length; i += 2) + for (uint i; i < intervals.length; i += 2) { auto a = intervals[i], b = intervals[i+1]; assert(a < b, text("illegal interval [a, b): ", a, " > ", b)); @@ -2215,7 +2215,7 @@ public: package auto scanFor()(dchar ch) const { immutable len = data.length; - for (size_t i = 0; i < len; i++) + for (size_t i; i < len; i++) if (ch < data[i]) return i & 1; return 0; @@ -2224,7 +2224,7 @@ public: /// Number of $(CODEPOINTS) in this set @property size_t length() { - size_t sum = 0; + size_t sum; foreach (iv; byInterval) { sum += iv.b - iv.a; @@ -2885,7 +2885,7 @@ private: // the last kept element (at 'i'). // - predicate mutates lhs (merges rhs into lhs) size_t len = ivals.length; - size_t i = 0; + size_t i; size_t j = 1; while (j < len) { @@ -2905,7 +2905,7 @@ private: } } len = i + 1; - for (size_t k=0; k + 1 < len; k++) + for (size_t k; k + 1 < len; k++) { assert(ivals[k].a < ivals[k].b); assert(ivals[k].b < ivals[k+1].a); @@ -4245,7 +4245,7 @@ template isValidArgsForTrie(Key, Args...) @property size_t sumOfIntegerTuple(ints...)() { - size_t count=0; + size_t count; foreach (v; ints) count += v; return count; @@ -5415,7 +5415,7 @@ if (is(C : wchar) || is(C : char)) { assert(collectException((){ auto s = msg; - size_t idx = 0; + size_t idx; utf8.test(s); }()), format("%( %2x %)", cast(ubyte[]) msg)); } @@ -5648,7 +5648,7 @@ template Sequence(size_t start, size_t end) assert(trie[a]); for (int a='A'; a<'Z';a++) assert(trie[a]); - for (int a=0; a<'A'; a++) + for (int a; a<'A'; a++) assert(!trie[a]); for (int a ='Z'; a<'a'; a++) assert(!trie[a]); @@ -5824,7 +5824,7 @@ package ubyte[] compressIntervals(Range)(Range intervals) if (isInputRange!Range && isIntegralPair!(ElementType!Range)) { ubyte[] storage; - uint base = 0; + uint base; // RLE encode foreach (val; intervals) { @@ -5850,7 +5850,7 @@ if (isInputRange!Range && isIntegralPair!(ElementType!Range)) auto run2 = [tuple(0, (1 << 20)+512+1), tuple((1 << 20)+512+4, lastDchar+1)]; ubyte[] enc2 = [cast(ubyte) 0, (0b1_01 << 5) | (1 << 4), 2, 1, 3]; // odd length-ed assert(compressIntervals(run2) == enc2); - size_t idx = 0; + size_t idx; assert(decompressFrom(enc, idx) == 80); assert(decompressFrom(enc, idx) == 47); assert(decompressFrom(enc, idx) == 1); @@ -6611,7 +6611,7 @@ if (isInputRange!Range && is(Unqual!(ElementType!Range) == Grapheme)) static struct Result { private Range _range; - private size_t i = 0; + private size_t i; bool empty() @property { @@ -6928,7 +6928,7 @@ private: enum nbytes = 3 * (grow + 1); size_t k = smallLength; ubyte* p = cast(ubyte*) enforce(malloc(nbytes), "malloc failed"); - for (int i=0; i 0) foreach (tidx, T; AllowedTypes) { - bool added = false; + bool added; foreach (dgidx, dg; Handler) { // Handle normal function objects @@ -2625,7 +2625,7 @@ if (isAlgebraic!VariantType && Handler.length > 0) --cnt; assert(cnt >= 0); } - static int cnt = 0; + static int cnt; } { diff --git a/std/windows/registry.d b/std/windows/registry.d index 0b5e3d2d1c3..b30b2b658e5 100644 --- a/std/windows/registry.d +++ b/std/windows/registry.d @@ -1512,7 +1512,7 @@ public: /// int opApply(scope int delegate(ref Key key) dg) { - int result = 0; + int result; regProcessNthKey(m_key.m_hkey, (scope LONG delegate(DWORD, out string) getName) { for (DWORD index = 0; !result; ++index) @@ -1621,7 +1621,7 @@ public: /// int opApply(scope int delegate(ref string name) dg) { - int result = 0; + int result; regProcessNthValue(m_key.m_hkey, (scope LONG delegate(DWORD, out string) getName) { for (DWORD index = 0; !result; ++index) @@ -1715,7 +1715,7 @@ public: /// int opApply(scope int delegate(ref Value value) dg) { - int result = 0; + int result; regProcessNthValue(m_key.m_hkey, (scope LONG delegate(DWORD, out string) getName) { for (DWORD index = 0; !result; ++index) diff --git a/std/windows/syserror.d b/std/windows/syserror.d index 863e0c1700c..3fc645e2083 100644 --- a/std/windows/syserror.d +++ b/std/windows/syserror.d @@ -91,7 +91,7 @@ string sysErrorString( bool putSysError(Writer)(DWORD code, Writer w, /*WORD*/int langId = 0) { - wchar *lpMsgBuf = null; + wchar *lpMsgBuf; auto res = FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | diff --git a/std/xml.d b/std/xml.d index 770c56fdbfb..087850e8140 100644 --- a/std/xml.d +++ b/std/xml.d @@ -489,7 +489,7 @@ string decode(string s, DecodeMode mode=DecodeMode.LOOSE) @safe pure { void assertNot(string s) pure { - bool b = false; + bool b; try { decode(s,DecodeMode.STRICT); } catch (DecodeException e) { b = true; } assert(b,s); @@ -862,7 +862,7 @@ class Element : Item override int opCmp(scope const Object o) @safe const { const element = toType!(const Element)(o); - for (uint i=0; ; ++i) + for (uint i; ; ++i) { if (i == items.length && i == element.items.length) return 0; if (i == items.length) return -1; @@ -2428,7 +2428,7 @@ private } catch (Err e) { fail(e); } - int n = 0; + int n; if (s.startsWith("'yes'") || s.startsWith("\"yes\"")) n = 5; else if (s.startsWith("'no'" ) || s.startsWith("\"no\"" )) n = 4; else fail("standalone attribute value must be 'yes', \"yes\","~ @@ -2555,7 +2555,7 @@ private while (s.length != 0) { immutable char d = s[0]; - int n = 0; + int n; switch (d) { case 'F','f': ++n; goto case; @@ -2817,7 +2817,7 @@ EOS"; `; DocumentParser parser = new DocumentParser(test_xml); - bool tested = false; + bool tested; parser.onStartTag["stream:stream"] = (ElementParser p) { assert(p.tag.attr["xmlns"] == "jabber:'client'"); assert(p.tag.attr["from"] == "jid.pl"); @@ -2903,8 +2903,8 @@ class CheckException : XMLException * or specific error message */ string msg; - size_t line = 0; /// Line number at which parse failure occurred - size_t column = 0; /// Column number at which parse failure occurred + size_t line; /// Line number at which parse failure occurred + size_t column; /// Column number at which parse failure occurred private this(string tail,string msg,Err err=null) @safe pure { diff --git a/std/zip.d b/std/zip.d index 47a3aa27a78..844c3c1495f 100644 --- a/std/zip.d +++ b/std/zip.d @@ -394,8 +394,8 @@ final class ZipArchive throw new ZipException("archive comment longer than 65535"); // Compress each member; compute size - uint archiveSize = 0; - uint directorySize = 0; + uint archiveSize; + uint directorySize; auto directory = _directory.values().sort!((x, y) => x.index < y.index).release; foreach (ArchiveMember de; directory) { @@ -661,7 +661,7 @@ final class ZipArchive } i = directoryOffset; - for (int n = 0; n < numEntries; n++) + for (int n; n < numEntries; n++) { /* The format of an entry is: * 'PK' 1, 2 @@ -822,7 +822,7 @@ debug(print) @safe void arrayPrint(ubyte[] array) { printf("array %p,%d\n", cast(void*) array, array.length); - for (int i = 0; i < array.length; i++) + for (int i; i < array.length; i++) { printf("%02x ", array[i]); if (((i + 1) & 15) == 0) @@ -892,7 +892,7 @@ debug(print) // Test if packing and unpacking preserves order. auto rand = Mt19937(15966); string[] names; - int value = 0; + int value; // Generate a series of unique numbers as filenames. foreach (i; 0 .. 20) { diff --git a/std/zlib.d b/std/zlib.d index 7965f3055b0..98e5807d7b1 100644 --- a/std/zlib.d +++ b/std/zlib.d @@ -696,7 +696,7 @@ private import std.stdio; // smallish buffers - for (int idx = 0; idx < 25; idx++) + for (int idx; idx < 25; idx++) { char[] buf = new char[uniform(0, 100)]; @@ -715,7 +715,7 @@ private import std.stdio; } // larger buffers - for (int idx = 0; idx < 25; idx++) + for (int idx; idx < 25; idx++) { char[] buf = new char[uniform(0, 1000/*0000*/)]; diff --git a/unittest.d b/unittest.d index ac8e07c8483..6a8a72ffdf2 100644 --- a/unittest.d +++ b/unittest.d @@ -87,7 +87,7 @@ int main(string[] args) assert(c.im == 1); printf("args.length = %d\n", args.length); - for (int i = 0; i < args.length; i++) + for (int i; i < args.length; i++) printf("args[%d] = '%.*s'\n", i, args[i].length, args[i].ptr); int[3] x;