diff --git a/std/algorithm/iteration.d b/std/algorithm/iteration.d index 8c7b42f8d..8323688ff 100644 --- a/std/algorithm/iteration.d +++ b/std/algorithm/iteration.d @@ -2534,8 +2534,10 @@ template reduce(fun...) if (fun.length >= 1) foreach (/+auto ref+/ E e; r) // @@@4707@@@ { foreach (i, f; binfuns) - static assert(is(typeof(args[i] = f(args[i], e))), + { + static assert(!is(typeof(f(args[i], e))) || is(typeof(args[i] = f(args[i], e))), algoFormat("Incompatible function/seed/element: %s/%s/%s", fullyQualifiedName!f, Args[i].stringof, E.stringof)); + } static if (mustInitialize) if (initialized == false) { diff --git a/std/container/slist.d b/std/container/slist.d index b015aec7b..1db510450 100644 --- a/std/container/slist.d +++ b/std/container/slist.d @@ -430,6 +430,7 @@ assert(std.algorithm.equal(sl[], ["a", "b", "c", "d", "e"])); size_t insertAfter(Stuff)(Range r, Stuff stuff) { + initialize(); if (!_first) { enforce(!r._head); @@ -761,3 +762,11 @@ unittest r.front = 1; //test frontAssign assert(r.front == 1); } + +unittest +{ + // issue 14920 + SList!int s; + s.insertAfter(s[], 1); + assert(s.front == 1); +} diff --git a/std/internal/cstring.d b/std/internal/cstring.d index 43f946bee..bfacdb31f 100644 --- a/std/internal/cstring.d +++ b/std/internal/cstring.d @@ -90,7 +90,7 @@ auto tempCString(To = char, From)(From str) alias CF = Unqual!(ElementEncodingType!From); - enum To* useStack = null; + enum To* useStack = () @trusted { return cast(To*)size_t.max; }(); static struct Res { @@ -182,7 +182,14 @@ auto tempCString(To = char, From)(From str) } import std.utf : byUTF; static if (isSomeString!From) + { auto r = cast(const(CF)[])str; // because inout(CF) causes problems with byUTF + if (r is null) // Bugzilla 14980 + { + res._ptr = null; + return res; + } + } else alias r = str; foreach (const c; byUTF!(Unqual!To)(r)) @@ -232,8 +239,14 @@ nothrow @nogc unittest assert(tempCString(abc[].byWchar).buffPtr.asArray == abc); } +// Bugzilla 14980 +nothrow @nogc unittest +{ + const(char[]) str = null; + auto res = tempCString(str); + const char* ptr = res; + assert(ptr is null); +} version(Windows) alias tempCStringW = tempCString!(wchar, const(char)[]); - - diff --git a/std/range/package.d b/std/range/package.d index c89727f76..ea520914f 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -2824,36 +2824,13 @@ auto generate(Fun)(Fun fun) return Generator!(Fun)(fun); } -/// +/// ditto auto generate(alias fun)() if (isCallable!fun) { return Generator!(fun)(); } -//private struct Generator(bool onPopFront, bool runtime, Fun...) -private struct Generator(Fun...) -{ - static assert(Fun.length == 1); - static assert(isInputRange!Generator); - -private: - static if (is(Fun[0])) - Fun[0] fun; - else - alias fun = Fun[0]; - -public: - enum empty = false; - - auto ref front() @property - { - return fun(); - } - - void popFront() { } -} - /// @safe pure unittest { @@ -2879,6 +2856,38 @@ public: assert(equal(generate(infiniteIota(1, 4)).take(10), [1, 2, 3, 1, 2, 3, 1, 2, 3, 1])); } +/// +unittest +{ + import std.format, std.random; + + auto r = generate!(() => uniform(0, 6)).take(10); + format("%(%s %)", r); +} + +//private struct Generator(bool onPopFront, bool runtime, Fun...) +private struct Generator(Fun...) +{ + static assert(Fun.length == 1); + static assert(isInputRange!Generator); + +private: + static if (is(Fun[0])) + Fun[0] fun; + else + alias fun = Fun[0]; + +public: + enum empty = false; + + auto ref front() @property + { + return fun(); + } + + void popFront() { } +} + @safe unittest { import std.algorithm : equal; diff --git a/std/socket.d b/std/socket.d index cc790ba1b..ea0803b17 100644 --- a/std/socket.d +++ b/std/socket.d @@ -1061,6 +1061,12 @@ unittest assert(results.length && results[0].family == AddressFamily.INET6); } }); + + if (getaddrinfoPointer) + { + auto results = getAddressInfo(null, "1234", AddressInfoFlags.PASSIVE, SocketType.STREAM, ProtocolType.TCP, AddressFamily.INET); + assert(results.length == 1 && results[0].address.toString() == "0.0.0.0:1234"); + } }