Fix DScanner warnings

This commit is contained in:
Sebastian Wilzbach 2018-02-09 18:29:38 +01:00
parent fcaf801cd1
commit d9830b739e
17 changed files with 104 additions and 82 deletions

View file

@ -851,6 +851,8 @@ pure @safe unittest
++ctr;
return 0;
}
bool opEquals(T)(T o) const { return false; }
size_t toHash() const { return 0; }
}
immutable S[4] a;
immutable S[4] b;
@ -869,6 +871,8 @@ nothrow pure @safe unittest
{
return value - rhs.value;
}
bool opEquals(T)(T o) const { return false; }
size_t toHash() const { return 0; }
}
auto result = cmp([F(1), F(2), F(3)], [F(1), F(2), F(3)]);
assert(result == 0);

View file

@ -4689,6 +4689,47 @@ if (isSomeChar!C)
}
}
// In same combinations substitute needs to calculate the auto-decoded length
// of its needles
private template hasDifferentAutodecoding(Range, Needles...)
{
import std.meta : anySatisfy;
/* iff
- the needles needs auto-decoding, but the incoming range doesn't (or vice versa)
- both (range, needle) need auto-decoding and don't share the same common type
*/
enum needlesAreNarrow = anySatisfy!(isNarrowString, Needles);
enum sourceIsNarrow = isNarrowString!Range;
enum hasDifferentAutodecoding = sourceIsNarrow != needlesAreNarrow ||
(sourceIsNarrow && needlesAreNarrow &&
is(CommonType!(Range, Needles) == void));
}
@safe nothrow @nogc pure unittest
{
import std.meta : AliasSeq; // used for better clarity
static assert(!hasDifferentAutodecoding!(string, AliasSeq!(string, string)));
static assert(!hasDifferentAutodecoding!(wstring, AliasSeq!(wstring, wstring)));
static assert(!hasDifferentAutodecoding!(dstring, AliasSeq!(dstring, dstring)));
// the needles needs auto-decoding, but the incoming range doesn't (or vice versa)
static assert(hasDifferentAutodecoding!(string, AliasSeq!(wstring, wstring)));
static assert(hasDifferentAutodecoding!(string, AliasSeq!(dstring, dstring)));
static assert(hasDifferentAutodecoding!(wstring, AliasSeq!(string, string)));
static assert(hasDifferentAutodecoding!(wstring, AliasSeq!(dstring, dstring)));
static assert(hasDifferentAutodecoding!(dstring, AliasSeq!(string, string)));
static assert(hasDifferentAutodecoding!(dstring, AliasSeq!(wstring, wstring)));
// both (range, needle) need auto-decoding and don't share the same common type
static foreach (T; AliasSeq!(string, wstring, dstring))
{
static assert(hasDifferentAutodecoding!(T, AliasSeq!(wstring, string)));
static assert(hasDifferentAutodecoding!(T, AliasSeq!(dstring, string)));
static assert(hasDifferentAutodecoding!(T, AliasSeq!(wstring, dstring)));
}
}
// substitute
/**
Returns a range with all occurrences of `substs` in `r`.
@ -4731,14 +4772,16 @@ if (substs.length >= 2 && isExpressions!substs)
// Substitute single range elements with compile-time substitution mappings
return value.map!(a => substitute(a));
}
else static if (isInputRange!Value && !is(CommonType!(ElementType!Value, ElementType!(typeof(substs[0]))) == void))
else static if (isInputRange!Value &&
!is(CommonType!(ElementType!Value, ElementType!(typeof(substs[0]))) == void))
{
// not implemented yet, fallback to runtime variant for now
return .substitute(value, substs);
}
else
{
static assert(0, "Compile-time substitutions must be elements or ranges of the same type of ` ~ Value.stringof ~ `.");
static assert(0, `Compile-time substitutions must be elements or ranges of the same type of ` ~
Value.stringof ~ `.`);
}
}
// Substitute single values with compile-time substitution mappings.
@ -4756,47 +4799,6 @@ if (substs.length >= 2 && isExpressions!substs)
}
}
// In same combinations substitute needs to calculate the auto-decoded length
// of its needles
private template hasDifferentAutodecoding(Range, Needles...)
{
import std.meta : anySatisfy;
/* iff
- the needles needs auto-decoding, but the incoming range doesn't (or vice versa)
- both (range, needle) need auto-decoding and don't share the same common type
*/
enum needlesAreNarrow = anySatisfy!(isNarrowString, Needles);
enum sourceIsNarrow = isNarrowString!Range;
enum hasDifferentAutodecoding = sourceIsNarrow != needlesAreNarrow ||
(sourceIsNarrow && needlesAreNarrow &&
is(CommonType!(Range, Needles) == void));
}
@safe nothrow @nogc pure unittest
{
import std.meta : AliasSeq; // used for better clarity
static assert(!hasDifferentAutodecoding!(string, AliasSeq!(string, string)));
static assert(!hasDifferentAutodecoding!(wstring, AliasSeq!(wstring, wstring)));
static assert(!hasDifferentAutodecoding!(dstring, AliasSeq!(dstring, dstring)));
// the needles needs auto-decoding, but the incoming range doesn't (or vice versa)
static assert(hasDifferentAutodecoding!(string, AliasSeq!(wstring, wstring)));
static assert(hasDifferentAutodecoding!(string, AliasSeq!(dstring, dstring)));
static assert(hasDifferentAutodecoding!(wstring, AliasSeq!(string, string)));
static assert(hasDifferentAutodecoding!(wstring, AliasSeq!(dstring, dstring)));
static assert(hasDifferentAutodecoding!(dstring, AliasSeq!(string, string)));
static assert(hasDifferentAutodecoding!(dstring, AliasSeq!(wstring, wstring)));
// both (range, needle) need auto-decoding and don't share the same common type
static foreach (T; AliasSeq!(string, wstring, dstring))
{
static assert(hasDifferentAutodecoding!(T, AliasSeq!(wstring, string)));
static assert(hasDifferentAutodecoding!(T, AliasSeq!(dstring, string)));
static assert(hasDifferentAutodecoding!(T, AliasSeq!(wstring, dstring)));
}
}
/// ditto
auto substitute(alias pred = (a, b) => a == b, R, Substs...)(R r, Substs substs)
if (isInputRange!R && Substs.length >= 2 && !is(CommonType!(Substs) == void))

View file

@ -1138,10 +1138,13 @@ if (isBidirectionalRange!R &&
static if (isDefaultPred && isSomeChar!E && E.sizeof <= ElementEncodingType!R.sizeof)
return doesThisEnd[$ - 1] == withThis;
// specialize for ASCII as to not change previous behavior
else if (withThis <= 0x7F)
return predFunc(doesThisEnd[$ - 1], withThis);
else
return predFunc(doesThisEnd.back, withThis);
{
if (withThis <= 0x7F)
return predFunc(doesThisEnd[$ - 1], withThis);
else
return predFunc(doesThisEnd.back, withThis);
}
}
else
{
@ -4263,10 +4266,13 @@ if (isInputRange!R &&
static if (isDefaultPred && isSomeChar!E && E.sizeof <= ElementEncodingType!R.sizeof)
return doesThisStart[0] == withThis;
// specialize for ASCII as to not change previous behavior
else if (withThis <= 0x7F)
return predFunc(doesThisStart[0], withThis);
else
return predFunc(doesThisStart.front, withThis);
{
if (withThis <= 0x7F)
return predFunc(doesThisStart[0], withThis);
else
return predFunc(doesThisStart.front, withThis);
}
}
else
{