mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 15:10:46 +03:00
Get rid of unused variables
This commit is contained in:
parent
bdcbb419e9
commit
55120ef91a
5 changed files with 62 additions and 43 deletions
|
@ -157,7 +157,7 @@ undocumented_declaration_check="-etc.c.curl,-etc.c.odbc.sql,-etc.c.odbc.sqlext,-
|
|||
; Checks for unused labels
|
||||
unused_label_check="-std.conv,-std.format,-std.internal.math.biguintx86,-std.regex.internal.thompson,-std.signals,-std.uni"
|
||||
; Checks for unused variables and function parameters
|
||||
unused_variable_check="-std.algorithm.comparison,-std.array,-std.bigint,-std.bitmanip,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.numeric,-std.parallelism,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex.internal.backtracking,-std.regex.internal.tests,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.windows.registry,-std.xml,-std.zip,-std.zlib"
|
||||
unused_variable_check="-std.algorithm.comparison,-std.array,-std.bitmanip,-std.complex,-std.concurrency,-std.container,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.container.slist,-std.conv,-std.csv,-std.datetime,-std.datetime.date,-std.datetime.interval,-std.datetime.stopwatch,-std.datetime.systime,-std.datetime.timezone,-std.digest.crc,-std.digest,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.digest.sha,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.affix_allocator,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.bucketizer,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.building_blocks.stats_collector,-std.experimental.allocator.common,-std.experimental.allocator.gc_allocator,-std.experimental.allocator.mallocator,-std.experimental.allocator.typed,-std.experimental.checkedint,-std.experimental.logger.core,-std.experimental.typecons,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintx86,-std.internal.math.errorfunction,-std.internal.scopebuffer,-std.internal.test.dummyrange,-std.json,-std.math,-std.meta,-std.mmfile,-std.net.curl,-std.numeric,-std.parallelism,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex.internal.backtracking,-std.regex.internal.tests,-std.regex.internal.thompson,-std.signals,-std.socket,-std.traits,-std.typecons,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.windows.registry,-std.xml,-std.zip,-std.zlib"
|
||||
; Check for useless user defined initializers
|
||||
useless_initializer="+disabled"
|
||||
;useless_initializer="-etc.c.odbc.sqlext,-etc.c.zlib,-std.algorithm.iteration,-std.algorithm.mutation,-std.algorithm.searching,-std.algorithm.setops,-std.algorithm.sorting,-std.array,-std.bigint,-std.bitmanip,-std.compiler,-std.container.array,-std.container.dlist,-std.container.rbtree,-std.conv,-std.csv,-std.datetime.systime,-std.digest.md,-std.digest.murmurhash,-std.digest.ripemd,-std.encoding,-std.exception,-std.experimental.allocator,-std.experimental.allocator.building_blocks.bitmapped_block,-std.experimental.allocator.building_blocks.free_tree,-std.experimental.allocator.building_blocks.kernighan_ritchie,-std.experimental.allocator.common,-std.experimental.allocator.mallocator,-std.experimental.logger.core,-std.experimental.logger.multilogger,-std.file,-std.format,-std.functional,-std.getopt,-std.internal.cstring,-std.internal.digest.sha_SSSE3,-std.internal.math.biguintcore,-std.internal.math.biguintnoasm,-std.internal.math.biguintx86,-std.internal.math.gammafunction,-std.internal.test.dummyrange,-std.json,-std.math,-std.net.curl,-std.numeric,-std.parallelism,-std.path,-std.process,-std.random,-std.range,-std.range.interfaces,-std.range.primitives,-std.regex,-std.regex.internal.backtracking,-std.regex.internal.generator,-std.regex.internal.ir,-std.regex.internal.kickstart,-std.regex.internal.parser,-std.regex.internal.tests,-std.regex.internal.thompson,-std.signals,-std.socket,-std.stdio,-std.string,-std.uni,-std.uri,-std.utf,-std.uuid,-std.variant,-std.windows.registry,-std.windows.syserror,-std.xml,-std.zip,-std.zlib"
|
||||
|
|
74
std/array.d
74
std/array.d
|
@ -163,7 +163,7 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
|
|||
struct Foo
|
||||
{
|
||||
int a;
|
||||
void opAssign(Foo foo)
|
||||
void opAssign(Foo)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
@ -189,6 +189,7 @@ if (isIterable!Range && !isNarrowString!Range && !isInfinite!Range)
|
|||
import std.range;
|
||||
static struct S{int* p;}
|
||||
auto a = array(immutable(S).init.repeat(5));
|
||||
assert(a.length == 5);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -257,11 +258,10 @@ if (isNarrowString!String)
|
|||
}
|
||||
|
||||
auto a = array([1, 2, 3, 4, 5][]);
|
||||
//writeln(a);
|
||||
assert(a == [ 1, 2, 3, 4, 5 ]);
|
||||
|
||||
auto b = array([TestArray(1), TestArray(2)][]);
|
||||
//writeln(b);
|
||||
assert(b == [TestArray(1), TestArray(2)]);
|
||||
|
||||
class C
|
||||
{
|
||||
|
@ -270,11 +270,12 @@ if (isNarrowString!String)
|
|||
override string toString() const @safe { return to!string(x); }
|
||||
}
|
||||
auto c = array([new C(1), new C(2)][]);
|
||||
//writeln(c);
|
||||
assert(c[0].x == 1);
|
||||
assert(c[1].x == 2);
|
||||
|
||||
auto d = array([1.0, 2.2, 3][]);
|
||||
assert(is(typeof(d) == double[]));
|
||||
//writeln(d);
|
||||
assert(d == [1.0, 2.2, 3]);
|
||||
|
||||
auto e = [OpAssign(1), OpAssign(2)];
|
||||
auto f = array(e);
|
||||
|
@ -416,6 +417,7 @@ if (isInputRange!Range)
|
|||
import std.typecons;
|
||||
auto a = [tuple!(const string, string)("foo", "bar")];
|
||||
auto b = [tuple!(string, const string)("foo", "bar")];
|
||||
assert(a == b);
|
||||
assert(assocArray(a) == [cast(const(string)) "foo": "bar"]);
|
||||
static assert(!__traits(compiles, assocArray(b)));
|
||||
}
|
||||
|
@ -750,6 +752,7 @@ private auto arrayAllocImpl(bool minimallyInitialized, T, I...)(I sizes) nothrow
|
|||
auto a = minimallyInitializedArray!(S[])(1);
|
||||
assert(a[0].p == null);
|
||||
enum b = minimallyInitializedArray!(S[])(1);
|
||||
assert(b[0].p == null);
|
||||
}
|
||||
|
||||
@safe nothrow unittest
|
||||
|
@ -760,21 +763,25 @@ private auto arrayAllocImpl(bool minimallyInitialized, T, I...)(I sizes) nothrow
|
|||
this(this) @disable;
|
||||
}
|
||||
auto a1 = minimallyInitializedArray!(S1[][])(2, 2);
|
||||
//enum b1 = minimallyInitializedArray!(S1[][])(2, 2);
|
||||
assert(a1);
|
||||
static struct S2
|
||||
{
|
||||
this() @disable;
|
||||
//this(this) @disable;
|
||||
}
|
||||
auto a2 = minimallyInitializedArray!(S2[][])(2, 2);
|
||||
assert(a2);
|
||||
enum b2 = minimallyInitializedArray!(S2[][])(2, 2);
|
||||
assert(b2);
|
||||
static struct S3
|
||||
{
|
||||
//this() @disable;
|
||||
this(this) @disable;
|
||||
}
|
||||
auto a3 = minimallyInitializedArray!(S3[][])(2, 2);
|
||||
assert(a3);
|
||||
enum b3 = minimallyInitializedArray!(S3[][])(2, 2);
|
||||
assert(b3);
|
||||
}
|
||||
|
||||
// overlap
|
||||
|
@ -1082,8 +1089,7 @@ private template isInputRangeOrConvertible(E)
|
|||
import std.exception;
|
||||
|
||||
|
||||
bool test(T, U, V)(T orig, size_t pos, U toInsert, V result,
|
||||
string file = __FILE__, size_t line = __LINE__)
|
||||
bool test(T, U, V)(T orig, size_t pos, U toInsert, V result)
|
||||
{
|
||||
{
|
||||
static if (is(T == typeof(T.init.dup)))
|
||||
|
@ -1199,18 +1205,6 @@ private template isInputRangeOrConvertible(E)
|
|||
assert(arr[0] == 1);
|
||||
insertInPlace(arr, 1, Int(2), Int(3));
|
||||
assert(equal(arr, [1, 2, 3, 4, 5])); //check it works with postblit
|
||||
|
||||
version (none) // illustrates that insertInPlace() will not work with CTFE and postblit
|
||||
{
|
||||
static bool testctfe()
|
||||
{
|
||||
Int[] arr = [Int(1), Int(4), Int(5)];
|
||||
assert(arr[0] == 1);
|
||||
insertInPlace(arr, 1, Int(2), Int(3));
|
||||
return equal(arr, [1, 2, 3, 4, 5]); //check it works with postblit
|
||||
}
|
||||
enum E = testctfe();
|
||||
}
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
|
@ -1383,7 +1377,6 @@ if (isInputRange!S && !isDynamicArray!S)
|
|||
|
||||
foreach (S; AliasSeq!(string, wstring, dstring, char[], wchar[], dchar[]))
|
||||
{
|
||||
S s;
|
||||
immutable S t = "abc";
|
||||
|
||||
assert(replicate(to!S("1234"), 0) is null);
|
||||
|
@ -1818,6 +1811,7 @@ if (isInputRange!RoR &&
|
|||
assert(a[0].length == 3);
|
||||
auto temp = join(a, " ");
|
||||
assert(a[0].length == 3);
|
||||
assert(temp.length == 3);
|
||||
}
|
||||
|
||||
@safe unittest // Issue 14230
|
||||
|
@ -2455,8 +2449,7 @@ if (is(typeof(replace(array, from, to, stuff))))
|
|||
import std.exception;
|
||||
|
||||
|
||||
bool test(T, U, V)(T orig, size_t from, size_t to, U toReplace, V result,
|
||||
string file = __FILE__, size_t line = __LINE__)
|
||||
bool test(T, U, V)(T orig, size_t from, size_t to, U toReplace, V result)
|
||||
{
|
||||
{
|
||||
static if (is(T == typeof(T.init.dup)))
|
||||
|
@ -3540,6 +3533,7 @@ unittest
|
|||
S[] s = [ S(new C) ];
|
||||
|
||||
auto t = fastCopy(s); // Does not compile
|
||||
assert(t.length == 1);
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
|
@ -3558,6 +3552,8 @@ unittest
|
|||
|
||||
@safe unittest
|
||||
{
|
||||
import std.algorithm.comparison : equal;
|
||||
|
||||
//New appender signature tests
|
||||
alias mutARR = int[];
|
||||
alias conARR = const(int)[];
|
||||
|
@ -3567,27 +3563,40 @@ unittest
|
|||
conARR con;
|
||||
immARR imm;
|
||||
|
||||
{auto app = Appender!mutARR(mut);} //Always worked. Should work. Should not create a warning.
|
||||
auto app1 = Appender!mutARR(mut); //Always worked. Should work. Should not create a warning.
|
||||
app1.put(7);
|
||||
assert(equal(app1.data, [7]));
|
||||
static assert(!is(typeof(Appender!mutARR(con)))); //Never worked. Should not work.
|
||||
static assert(!is(typeof(Appender!mutARR(imm)))); //Never worked. Should not work.
|
||||
|
||||
{auto app = Appender!conARR(mut);} //Always worked. Should work. Should not create a warning.
|
||||
{auto app = Appender!conARR(con);} //Didn't work. Now works. Should not create a warning.
|
||||
{auto app = Appender!conARR(imm);} //Didn't work. Now works. Should not create a warning.
|
||||
auto app2 = Appender!conARR(mut); //Always worked. Should work. Should not create a warning.
|
||||
app2.put(7);
|
||||
assert(equal(app2.data, [7]));
|
||||
auto app3 = Appender!conARR(con); //Didn't work. Now works. Should not create a warning.
|
||||
app3.put(7);
|
||||
assert(equal(app3.data, [7]));
|
||||
auto app4 = Appender!conARR(imm); //Didn't work. Now works. Should not create a warning.
|
||||
app4.put(7);
|
||||
assert(equal(app4.data, [7]));
|
||||
|
||||
//{auto app = Appender!immARR(mut);} //Worked. Will cease to work. Creates warning.
|
||||
//static assert(!is(typeof(Appender!immARR(mut)))); //Worked. Will cease to work. Uncomment me after full deprecation.
|
||||
static assert(!is(typeof(Appender!immARR(con)))); //Never worked. Should not work.
|
||||
{auto app = Appender!immARR(imm);} //Didn't work. Now works. Should not create a warning.
|
||||
auto app5 = Appender!immARR(imm); //Didn't work. Now works. Should not create a warning.
|
||||
app5.put(7);
|
||||
assert(equal(app5.data, [7]));
|
||||
|
||||
//Deprecated. Please uncomment and make sure this doesn't work:
|
||||
//char[] cc;
|
||||
//static assert(!is(typeof(Appender!string(cc))));
|
||||
|
||||
//This should always work:
|
||||
{auto app = appender!string(null);}
|
||||
{auto app = appender!(const(char)[])(null);}
|
||||
{auto app = appender!(char[])(null);}
|
||||
auto app6 = appender!string(null);
|
||||
assert(app6.data == null);
|
||||
auto app7 = appender!(const(char)[])(null);
|
||||
assert(app7.data == null);
|
||||
auto app8 = appender!(char[])(null);
|
||||
assert(app8.data == null);
|
||||
}
|
||||
|
||||
@safe unittest //Test large allocations (for GC.extend)
|
||||
|
@ -3614,7 +3623,9 @@ unittest
|
|||
@safe unittest // clear method is supported only for mutable element types
|
||||
{
|
||||
Appender!string app;
|
||||
app.put("foo");
|
||||
static assert(!__traits(compiles, app.clear()));
|
||||
assert(app.data == "foo");
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
|
@ -3662,6 +3673,7 @@ unittest
|
|||
return [new shared A].inputRangeObject;
|
||||
}
|
||||
auto res = foo.array;
|
||||
assert(res.length == 1);
|
||||
}
|
||||
|
||||
/++
|
||||
|
|
15
std/bigint.d
15
std/bigint.d
|
@ -157,7 +157,7 @@ public:
|
|||
// @system due to failure in FreeBSD32
|
||||
ulong data = 1_000_000_000_000;
|
||||
auto bigData = BigInt(data);
|
||||
assert(data == BigInt("1_000_000_000_000"));
|
||||
assert(bigData == BigInt("1_000_000_000_000"));
|
||||
}
|
||||
|
||||
/// Construct a BigInt from another BigInt.
|
||||
|
@ -1020,7 +1020,9 @@ private:
|
|||
assert(h == a);
|
||||
assert(i == e);
|
||||
BigInt j = "-0x9A56_57f4_7B83_AB78";
|
||||
BigInt k = j;
|
||||
j ^^= 11;
|
||||
assert(k ^^ 11 == j);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1121,6 +1123,7 @@ unittest
|
|||
a = 1;
|
||||
b = 2;
|
||||
auto c = a + b;
|
||||
assert(c == 3);
|
||||
}
|
||||
|
||||
nothrow pure @system
|
||||
|
@ -1129,7 +1132,9 @@ unittest
|
|||
long a;
|
||||
BigInt b;
|
||||
auto c = a + b;
|
||||
assert(c == 0);
|
||||
auto d = b + a;
|
||||
assert(d == 0);
|
||||
}
|
||||
|
||||
nothrow pure @system
|
||||
|
@ -1500,8 +1505,8 @@ unittest
|
|||
const BigInt cbi = 3;
|
||||
immutable BigInt ibi = 3;
|
||||
|
||||
assert(__traits(compiles, foo(cbi)));
|
||||
assert(__traits(compiles, foo(ibi)));
|
||||
foo(cbi);
|
||||
foo(ibi);
|
||||
|
||||
import std.conv : to;
|
||||
import std.meta : AliasSeq;
|
||||
|
@ -1529,12 +1534,14 @@ unittest
|
|||
|
||||
BigInt n = 2;
|
||||
n *= 2;
|
||||
assert(n == 4);
|
||||
}
|
||||
|
||||
@safe unittest // 8167
|
||||
{
|
||||
BigInt a = BigInt(3);
|
||||
BigInt b = BigInt(a);
|
||||
assert(b == 3);
|
||||
}
|
||||
|
||||
@safe unittest // 9061
|
||||
|
@ -1620,6 +1627,7 @@ unittest
|
|||
assert(is(typeof(x % 1UL) == BigInt));
|
||||
|
||||
auto x1 = BigInt(8);
|
||||
assert(x1 / x == x1);
|
||||
auto x2 = -BigInt(long.min) + 1;
|
||||
|
||||
// long
|
||||
|
@ -1702,4 +1710,5 @@ unittest
|
|||
@system unittest
|
||||
{
|
||||
auto b = immutable BigInt("123");
|
||||
assert(b == 123);
|
||||
}
|
||||
|
|
|
@ -3401,7 +3401,7 @@ struct LockingTextReader
|
|||
auto deleteme = testFilename();
|
||||
std.file.write(deleteme, "1 2 3");
|
||||
scope(exit) std.file.remove(deleteme);
|
||||
int x, y;
|
||||
int x;
|
||||
auto f = File(deleteme);
|
||||
f.readf("%s ", &x);
|
||||
assert(x == 1);
|
||||
|
@ -3878,7 +3878,7 @@ uint readf(A...)(in char[] format, auto ref A args)
|
|||
@system unittest
|
||||
{
|
||||
float f;
|
||||
if (false) uint x = readf("%s", &f);
|
||||
if (false) readf("%s", &f);
|
||||
|
||||
char a;
|
||||
wchar b;
|
||||
|
@ -4143,8 +4143,6 @@ struct lines
|
|||
alias Parms = Parameters!(dg);
|
||||
static if (isSomeString!(Parms[$ - 1]))
|
||||
{
|
||||
enum bool duplicate = is(Parms[$ - 1] == string)
|
||||
|| is(Parms[$ - 1] == wstring) || is(Parms[$ - 1] == dstring);
|
||||
int result = 0;
|
||||
static if (is(Parms[$ - 1] : const(char)[]))
|
||||
alias C = char;
|
||||
|
@ -5071,7 +5069,6 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
|
|||
File f = File(deleteme, "rb");
|
||||
|
||||
char[] ln = new char[2];
|
||||
char* lnptr = ln.ptr;
|
||||
f.readln(ln);
|
||||
|
||||
assert(ln == "abcd\n");
|
||||
|
@ -5082,7 +5079,6 @@ private size_t readlnImpl(FILE* fps, ref char[] buf, dchar terminator, File.Orie
|
|||
|
||||
// it can also stomp the array length
|
||||
ln = new char[4];
|
||||
lnptr = ln.ptr;
|
||||
f.readln(ln);
|
||||
assert(ln == "0123456789abcde\n");
|
||||
|
||||
|
|
|
@ -3306,8 +3306,6 @@ if (isConvertibleToString!Range)
|
|||
import std.conv : to;
|
||||
import std.exception : assertCTFEable;
|
||||
|
||||
string s;
|
||||
|
||||
assertCTFEable!(
|
||||
{
|
||||
foreach (S; AliasSeq!(char[], wchar[], dchar[], string, wstring, dstring))
|
||||
|
@ -4808,6 +4806,7 @@ if (isSomeChar!C1 && isSomeChar!C2)
|
|||
auto s = to!S("hello world");
|
||||
dchar[dchar] transTable = ['h' : 'q', 'l' : '5'];
|
||||
static assert(is(typeof(s) == typeof(translate(s, transTable))));
|
||||
assert(translate(s, transTable) == "qe55o wor5d");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4874,6 +4873,7 @@ if (isSomeChar!C1 && isSomeString!S && isSomeChar!C2)
|
|||
auto s = to!S("hello world");
|
||||
string[dchar] transTable = ['h' : "silly", 'l' : "putty"];
|
||||
static assert(is(typeof(s) == typeof(translate(s, transTable))));
|
||||
assert(translate(s, transTable) == "sillyeputtyputtyo worputtyd");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -5101,6 +5101,7 @@ body
|
|||
auto s = to!(C[])("hello world");
|
||||
auto transTable = makeTransTable("hl", "q5");
|
||||
static assert(is(typeof(s) == typeof(translate!C(s, transTable))));
|
||||
assert(translate(s, transTable) == "qe55o wor5d");
|
||||
}
|
||||
|
||||
foreach (S; AliasSeq!(char[], const(char)[], immutable(char)[]))
|
||||
|
@ -5786,6 +5787,7 @@ C1[] tr(C1, C2, C3, C4 = immutable char)
|
|||
|
||||
auto s = to!S("hello world");
|
||||
static assert(is(typeof(s) == typeof(tr(s, "he", "if"))));
|
||||
assert(tr(s, "he", "if") == "ifllo world");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue