mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Merge pull request #1329 from 9rnsr/fix10220
[REG2.064a] Issue 10220 - `array` doesn't work with disabled default construction
This commit is contained in:
commit
7b0a1219fd
8 changed files with 89 additions and 58 deletions
69
std/array.d
69
std/array.d
|
@ -169,6 +169,27 @@ unittest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bugzilla 10220
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
import std.algorithm : equal;
|
||||||
|
import std.range : repeat;
|
||||||
|
|
||||||
|
static struct S
|
||||||
|
{
|
||||||
|
int val;
|
||||||
|
|
||||||
|
@disable this();
|
||||||
|
this(int v) { val = v; }
|
||||||
|
}
|
||||||
|
assertCTFEable!(
|
||||||
|
{
|
||||||
|
auto r = S(1).repeat(2).array();
|
||||||
|
assert(equal(r, [S(1), S(1)]));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns a newly allocated associative array out of elements of the input range,
|
Returns a newly allocated associative array out of elements of the input range,
|
||||||
which must be a range of tuples (Key, Value).
|
which must be a range of tuples (Key, Value).
|
||||||
|
@ -187,8 +208,8 @@ assert(b == ["foo":"bar", "baz":"quux"]);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto assocArray(Range)(Range r)
|
auto assocArray(Range)(Range r)
|
||||||
if (isInputRange!Range && isTuple!(ElementType!Range)
|
if (isInputRange!Range && isTuple!(ElementType!Range) &&
|
||||||
&& ElementType!Range.length == 2)
|
ElementType!Range.length == 2)
|
||||||
{
|
{
|
||||||
alias ElementType!Range.Types[0] KeyType;
|
alias ElementType!Range.Types[0] KeyType;
|
||||||
alias ElementType!Range.Types[1] ValueType;
|
alias ElementType!Range.Types[1] ValueType;
|
||||||
|
@ -202,7 +223,7 @@ unittest
|
||||||
{
|
{
|
||||||
static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray()));
|
static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray()));
|
||||||
static assert(!__traits(compiles, [ tuple("foo") ].assocArray()));
|
static assert(!__traits(compiles, [ tuple("foo") ].assocArray()));
|
||||||
static assert(__traits(compiles, [ tuple("foo", "bar") ].assocArray()));
|
static assert( __traits(compiles, [ tuple("foo", "bar") ].assocArray()));
|
||||||
|
|
||||||
auto aa1 = [ tuple("foo", "bar"), tuple("baz", "quux") ].assocArray();
|
auto aa1 = [ tuple("foo", "bar"), tuple("baz", "quux") ].assocArray();
|
||||||
assert(is(typeof(aa1) == string[string]));
|
assert(is(typeof(aa1) == string[string]));
|
||||||
|
@ -224,7 +245,8 @@ private template blockAttribute(T)
|
||||||
enum blockAttribute = GC.BlkAttr.NO_SCAN;
|
enum blockAttribute = GC.BlkAttr.NO_SCAN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unittest {
|
unittest
|
||||||
|
{
|
||||||
static assert(!(blockAttribute!void & GC.BlkAttr.NO_SCAN));
|
static assert(!(blockAttribute!void & GC.BlkAttr.NO_SCAN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +263,8 @@ private template nDimensions(T)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest {
|
unittest
|
||||||
|
{
|
||||||
static assert(nDimensions!(uint[]) == 1);
|
static assert(nDimensions!(uint[]) == 1);
|
||||||
static assert(nDimensions!(float[][]) == 2);
|
static assert(nDimensions!(float[][]) == 2);
|
||||||
}
|
}
|
||||||
|
@ -319,7 +342,12 @@ if(allSatisfy!(isIntegral, I))
|
||||||
alias typeof(T.init[0]) E;
|
alias typeof(T.init[0]) E;
|
||||||
|
|
||||||
auto ptr = (__ctfe) ?
|
auto ptr = (__ctfe) ?
|
||||||
(new E[](sizes[0])).ptr :
|
{
|
||||||
|
E[] arr;
|
||||||
|
foreach (i; 0 .. sizes[0])
|
||||||
|
arr ~= E.init;
|
||||||
|
return arr.ptr;
|
||||||
|
}() :
|
||||||
cast(E*) GC.malloc(sizes[0] * E.sizeof, blockAttribute!(E));
|
cast(E*) GC.malloc(sizes[0] * E.sizeof, blockAttribute!(E));
|
||||||
auto ret = ptr[0..sizes[0]];
|
auto ret = ptr[0..sizes[0]];
|
||||||
|
|
||||||
|
@ -1160,14 +1188,13 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
static int[] testCTFE()
|
assertCTFEable!(
|
||||||
{
|
{
|
||||||
int[] a = [1, 2];
|
int[] a = [1, 2];
|
||||||
a.insertInPlace(2, 3);
|
a.insertInPlace(2, 3);
|
||||||
a.insertInPlace(0, -1, 0);
|
a.insertInPlace(0, -1, 0);
|
||||||
return a;
|
return a == [-1, 0, 1, 2, 3];
|
||||||
}
|
});
|
||||||
static assert(testCTFE() == [-1, 0, 1, 2, 3]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest // bugzilla 6874
|
unittest // bugzilla 6874
|
||||||
|
@ -2586,23 +2613,19 @@ unittest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct S10122
|
||||||
{
|
{
|
||||||
static struct S10122
|
int val;
|
||||||
{
|
|
||||||
int val;
|
|
||||||
|
|
||||||
@disable this();
|
@disable this();
|
||||||
this(int v) { val = v; }
|
this(int v) { val = v; }
|
||||||
}
|
}
|
||||||
|
assertCTFEable!(
|
||||||
|
{
|
||||||
auto w = appender!(S10122[])();
|
auto w = appender!(S10122[])();
|
||||||
w.put(S10122(1));
|
w.put(S10122(1));
|
||||||
|
assert(w.data.length == 1 && w.data[0].val == 1);
|
||||||
static assert({
|
});
|
||||||
auto w = appender!(S10122[])();
|
|
||||||
w.put(S10122(1));
|
|
||||||
return w.data.length == 1 && w.data[0].val == 1;
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
|
17
std/conv.d
17
std/conv.d
|
@ -958,10 +958,12 @@ unittest
|
||||||
assert(wtext(int.min) == "-2147483648"w);
|
assert(wtext(int.min) == "-2147483648"w);
|
||||||
assert(to!string(0L) == "0");
|
assert(to!string(0L) == "0");
|
||||||
|
|
||||||
//Test CTFE-ability.
|
assertCTFEable!(
|
||||||
static assert(to!string(1uL << 62) == "4611686018427387904");
|
{
|
||||||
static assert(to!string(0x100000000) == "4294967296");
|
assert(to!string(1uL << 62) == "4611686018427387904");
|
||||||
static assert(to!string(-138L) == "-138");
|
assert(to!string(0x100000000) == "4294967296");
|
||||||
|
assert(to!string(-138L) == "-138");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -1995,10 +1997,9 @@ unittest
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
//Some CTFE-ability checks.
|
assertCTFEable!({ string s = "1234abc"; assert(parse! int(s) == 1234 && s == "abc"); });
|
||||||
static assert((){string s = "1234abc"; return parse!int(s) == 1234 && s == "abc";}());
|
assertCTFEable!({ string s = "-1234abc"; assert(parse! int(s) == -1234 && s == "abc"); });
|
||||||
static assert((){string s = "-1234abc"; return parse!int(s) == -1234 && s == "abc";}());
|
assertCTFEable!({ string s = "1234abc"; assert(parse!uint(s) == 1234 && s == "abc"); });
|
||||||
static assert((){string s = "1234abc"; return parse!uint(s) == 1234 && s == "abc";}());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
|
|
|
@ -1197,3 +1197,10 @@ unittest
|
||||||
static assert(!__traits(compiles, 1.ifThrown(e=>new Object())));
|
static assert(!__traits(compiles, 1.ifThrown(e=>new Object())));
|
||||||
static assert(!__traits(compiles, (new Object()).ifThrown(e=>1)));
|
static assert(!__traits(compiles, (new Object()).ifThrown(e=>1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version(unittest) package
|
||||||
|
@property void assertCTFEable(alias dg)()
|
||||||
|
{
|
||||||
|
static assert({ dg(); return true; }());
|
||||||
|
dg();
|
||||||
|
}
|
||||||
|
|
11
std/format.d
11
std/format.d
|
@ -3627,13 +3627,6 @@ void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = _
|
||||||
input, fn, ln);
|
input, fn, ln);
|
||||||
}
|
}
|
||||||
|
|
||||||
version(unittest)
|
|
||||||
@property void checkCTFEable(alias dg)()
|
|
||||||
{
|
|
||||||
static assert({ dg(); return true; }());
|
|
||||||
dg();
|
|
||||||
}
|
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
void booleanTest()
|
void booleanTest()
|
||||||
|
@ -3712,7 +3705,9 @@ unittest
|
||||||
formatReflectTest(aa, "{%([%s=%(%c%)]%|; %)}", `{[1=hello]; [2=world]}`);
|
formatReflectTest(aa, "{%([%s=%(%c%)]%|; %)}", `{[1=hello]; [2=world]}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCTFEable!({
|
import std.exception;
|
||||||
|
assertCTFEable!(
|
||||||
|
{
|
||||||
booleanTest();
|
booleanTest();
|
||||||
integerTest();
|
integerTest();
|
||||||
if (!__ctfe) floatingTest(); // snprintf
|
if (!__ctfe) floatingTest(); // snprintf
|
||||||
|
|
|
@ -1318,11 +1318,7 @@ unittest
|
||||||
[1.0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
|
[1.0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
|
||||||
static const y =
|
static const y =
|
||||||
[2.0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
|
[2.0, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
|
||||||
assert(dotProduct(x, y) == 2280);
|
assertCTFEable!({ assert(dotProduct(x, y) == 2280); });
|
||||||
|
|
||||||
// Test in CTFE
|
|
||||||
enum ctfeDot = dotProduct(x, y);
|
|
||||||
static assert(ctfeDot == 2280);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
19
std/path.d
19
std/path.d
|
@ -1619,8 +1619,11 @@ unittest
|
||||||
assert (equal2(pathSplitter(`\\foo\bar\baz`), [`\\foo\bar`, "baz"]));
|
assert (equal2(pathSplitter(`\\foo\bar\baz`), [`\\foo\bar`, "baz"]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// CTFE
|
import std.exception;
|
||||||
static assert (equal(pathSplitter("/foo/bar".dup), ["/", "foo", "bar"]));
|
assertCTFEable!(
|
||||||
|
{
|
||||||
|
assert (equal(pathSplitter("/foo/bar".dup), ["/", "foo", "bar"]));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1943,8 +1946,10 @@ unittest
|
||||||
assert (relativePath("/foo/bar/baz", "/foo/bar") == "baz");
|
assert (relativePath("/foo/bar/baz", "/foo/bar") == "baz");
|
||||||
assertThrown(relativePath("/foo", "bar"));
|
assertThrown(relativePath("/foo", "bar"));
|
||||||
|
|
||||||
// CTFE
|
assertCTFEable!(
|
||||||
static assert (relativePath("/foo/bar", "/foo/baz") == "../bar");
|
{
|
||||||
|
assert (relativePath("/foo/bar", "/foo/baz") == "../bar");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else version (Windows)
|
else version (Windows)
|
||||||
{
|
{
|
||||||
|
@ -1958,8 +1963,10 @@ unittest
|
||||||
assert (relativePath(`\\foo\bar`, `c:\foo`) == `\\foo\bar`);
|
assert (relativePath(`\\foo\bar`, `c:\foo`) == `\\foo\bar`);
|
||||||
assertThrown(relativePath(`c:\foo`, "bar"));
|
assertThrown(relativePath(`c:\foo`, "bar"));
|
||||||
|
|
||||||
// CTFE
|
assertCTFEable!(
|
||||||
static assert (relativePath(`c:\foo\bar`, `c:\foo\baz`) == `..\bar`);
|
{
|
||||||
|
assert (relativePath(`c:\foo\bar`, `c:\foo\baz`) == `..\bar`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else static assert (0);
|
else static assert (0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2365,9 +2365,11 @@ unittest
|
||||||
assertThrown!FormatException(format("foo %s"));
|
assertThrown!FormatException(format("foo %s"));
|
||||||
assertThrown!FormatException(format("foo %s", 123, 456));
|
assertThrown!FormatException(format("foo %s", 123, 456));
|
||||||
|
|
||||||
//Test CTFE-ability of format.
|
assertCTFEable!(
|
||||||
static assert(format("hel%slo%s%s%s", "world", -138, 'c', true) ==
|
{
|
||||||
"helworldlo-138ctrue", "[" ~ s ~ "]");
|
assert(format("hel%slo%s%s%s", "world", -138, 'c', true) ==
|
||||||
|
"helworldlo-138ctrue");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -829,12 +829,12 @@ unittest
|
||||||
}
|
}
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
static assert({
|
// Bugzilla 10218
|
||||||
|
assertCTFEable!(
|
||||||
|
{
|
||||||
auto t = tuple(1);
|
auto t = tuple(1);
|
||||||
t = tuple(2);
|
t = tuple(2); // assignment
|
||||||
|
});
|
||||||
return true;
|
|
||||||
}());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue