mirror of
https://github.com/dlang/phobos.git
synced 2025-05-03 00:20:26 +03:00
Fix issue 23668: TimSort must avoid default initialization if the type being sorted has it disabled.
This commit is contained in:
parent
a4592ef56d
commit
c06e3171f1
1 changed files with 22 additions and 2 deletions
|
@ -2599,9 +2599,17 @@ private template TimSortImpl(alias pred, R)
|
||||||
//Test for overflow
|
//Test for overflow
|
||||||
if (newSize < minCapacity) newSize = minCapacity;
|
if (newSize < minCapacity) newSize = minCapacity;
|
||||||
|
|
||||||
|
// can't use `temp.length` if there's no default constructor
|
||||||
|
static if (__traits(compiles, { T defaultConstructed; cast(void) defaultConstructed; }))
|
||||||
|
{
|
||||||
if (__ctfe) temp.length = newSize;
|
if (__ctfe) temp.length = newSize;
|
||||||
else temp = () @trusted { return uninitializedArray!(T[])(newSize); }();
|
else temp = () @trusted { return uninitializedArray!(T[])(newSize); }();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
temp = () @trusted { return uninitializedArray!(T[])(newSize); }();
|
||||||
|
}
|
||||||
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3037,6 +3045,18 @@ private template TimSortImpl(alias pred, R)
|
||||||
sort!(cmp, SwapStrategy.stable)(makeArray(minMerge + 5));
|
sort!(cmp, SwapStrategy.stable)(makeArray(minMerge + 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=23668
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
static struct S
|
||||||
|
{
|
||||||
|
int opCmp(const S) const { return 1; }
|
||||||
|
@disable this();
|
||||||
|
}
|
||||||
|
S[] array;
|
||||||
|
array.sort!("a < b", SwapStrategy.stable);
|
||||||
|
}
|
||||||
|
|
||||||
// schwartzSort
|
// schwartzSort
|
||||||
/**
|
/**
|
||||||
Alternative sorting method that should be used when comparing keys involves an
|
Alternative sorting method that should be used when comparing keys involves an
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue