Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ style: publictests style_lint
# runs static code analysis with Dscanner
dscanner: | $(DSCANNER_DIR)/dsc
@echo "Running DScanner"
$(DEBUGGER) -q -ex run -ex bt -batch --args $(DSCANNER_DIR)/dsc --config .dscanner.ini --styleCheck etc std -I.
$(DEBUGGER) -return-child-result -q -ex run -ex bt -batch --args $(DSCANNER_DIR)/dsc --config .dscanner.ini --styleCheck etc std -I.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: DScanner doesn't seem to be super stable, so imho it's better to keep running it within GDB for a while. The overhead isn't too big and we have done so for the last two months.


style_lint: dscanner $(LIB)
@echo "Check for trailing whitespace"
Expand Down
4 changes: 4 additions & 0 deletions std/algorithm/comparison.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
88 changes: 45 additions & 43 deletions std/algorithm/iteration.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed to for the "public symbol without undocumented example" check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. This symbol is not documented and the unit test is not an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning was for template substitute. I don't remember which one, but one of the documentation engines used to dislike different symbols (even if they are private) between declaration and unittest. It looks like this has been fixed, so I can look into updating DScanner... though maybe we can live with this workaround until DScanner has been upgraded?


// substitute
/**
Returns a range with all occurrences of `substs` in `r`.
Expand Down Expand Up @@ -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))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line > 120

{
// 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 ` ~
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line > 120

Value.stringof ~ `.`);
}
}
// Substitute single values with compile-time substitution mappings.
Expand All @@ -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))
Expand Down
18 changes: 12 additions & 6 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions std/bigint.d
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,7 @@ unittest

enum BigInt test1 = BigInt(123);
enum BigInt test2 = plusTwo(test1);
assert(test2 == 125);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test2 is never used.

}

/**
Expand Down
2 changes: 0 additions & 2 deletions std/datetime/systime.d
Original file line number Diff line number Diff line change
Expand Up @@ -10322,7 +10322,6 @@ if (isSomeString!S)
import std.ascii : isDigit;
import std.conv : to;
import std.string : representation;
import core.time;

if (isoString.empty)
return Duration.zero;
Expand Down Expand Up @@ -10963,7 +10962,6 @@ version(StdUnittest)

void initializeTests() @safe
{
import core.time;
import std.algorithm.sorting : sort;
import std.typecons : Rebindable;
immutable lt = LocalTime().utcToTZ(0);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports

Expand Down
9 changes: 6 additions & 3 deletions std/digest/sha.d
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,8 @@ alias SHA512_256 = SHA!(1024, 256); /// SHA alias for SHA-512/256, hash is ubyte
sha256.put(cast(ubyte[])"abcdef");
sha256.start();
sha256.put(cast(ubyte[])"");
assert(sha256.finish() == cast(ubyte[]) hexString!"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
assert(sha256.finish() == cast(ubyte[])
hexString!"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");

SHA384 sha384;
sha384.put(cast(ubyte[])"abcdef");
Expand All @@ -922,7 +923,8 @@ alias SHA512_256 = SHA!(1024, 256); /// SHA alias for SHA-512/256, hash is ubyte
sha512.put(cast(ubyte[])"abcdef");
sha512.start();
sha512.put(cast(ubyte[])"");
assert(sha512.finish() == cast(ubyte[]) hexString!("cf83e1357eefb8bdf1542850d66d8007d620e4050b571"
assert(sha512.finish() == cast(ubyte[])
hexString!("cf83e1357eefb8bdf1542850d66d8007d620e4050b571"
~"5dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"));

SHA512_224 sha512_224;
Expand All @@ -935,7 +937,8 @@ alias SHA512_256 = SHA!(1024, 256); /// SHA alias for SHA-512/256, hash is ubyte
sha512_256.put(cast(ubyte[])"abcdef");
sha512_256.start();
sha512_256.put(cast(ubyte[])"");
assert(sha512_256.finish() == cast(ubyte[]) hexString!"c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a");
assert(sha512_256.finish() == cast(ubyte[])
hexString!"c672b8d1ef56ed28ab87c3622c5114069bdd3ad7b8f9737498d0c01ecef0967a");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long lines


digest = sha1Of ("");
digest224 = sha224Of ("");
Expand Down
2 changes: 1 addition & 1 deletion std/exception.d
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ T enforce(T)(T value, lazy Throwable ex)
}

///
unittest
@system unittest
{
import core.stdc.stdlib : malloc, free;
import std.conv : ConvException, to;
Expand Down
8 changes: 4 additions & 4 deletions std/experimental/allocator/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ nothrow:
}
}

unittest
@system unittest
{
import std.experimental.allocator.building_blocks.region : Region;
import std.conv : emplace;
Expand All @@ -553,7 +553,7 @@ unittest
assert((cast(CAllocatorImpl!(Region!(), Yes.indirect))(rcalloc._alloc)).rc == 1);
}

unittest
@system unittest
{
import std.conv;
import std.experimental.allocator.mallocator;
Expand All @@ -576,7 +576,7 @@ unittest
~ to!string(bytesUsed) ~ " bytes");
}

unittest
@system unittest
{
import std.conv;
import std.experimental.allocator.mallocator;
Expand Down Expand Up @@ -2554,7 +2554,7 @@ RCIAllocator allocatorObject(A)(A* pa)
assert(a.deallocate(b));
}

unittest
@system unittest
{
import std.conv;
import std.experimental.allocator.mallocator;
Expand Down
2 changes: 1 addition & 1 deletion std/experimental/scripting.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module std.experimental.scripting;
import std.experimental.scripting;

int len;
auto r = 6.iota
const r = 6.iota
.filter!(a => a % 2) // 0 2 4
.map!(a => a * 2) // 0 4 8
.tee!(_ => len++)
Expand Down
2 changes: 1 addition & 1 deletion std/format.d
Original file line number Diff line number Diff line change
Expand Up @@ -4047,7 +4047,7 @@ if ((is(T == struct) || is(T == union)) && (hasToString!(T, Char) || !is(Builtin
assert(w.data == "S()");
}

unittest
@safe unittest
{
//struct Foo { @disable string toString(); }
//Foo foo;
Expand Down
2 changes: 1 addition & 1 deletion std/math.d
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ template isDeprecatedComplex(T)
}
}

deprecated unittest
@safe deprecated unittest
{
static assert(isDeprecatedComplex!cfloat);
static assert(isDeprecatedComplex!cdouble);
Expand Down
Loading