Comment #0 by joseph.wakeling — 2014-06-08T16:40:43Z
The uniform!T specialization, which returns a random variate covering the entire bit range of an integral or character type T, will fail in the event that T == dchar because dchar.max is significantly less than the largest number that can be stored in dchar's 32 bits.
This in turn leads uniform!"[]"(dchar.min, dchar.max) to fail, because the integral/character-type uniform() calls uniform!ReturnType in the event of a closed interval with bounds [ReturnType.min, ReturnType.max].
See forum discussion for further details, including code that illustrates the bug: http://forum.dlang.org/thread/[email protected]
Comment #1 by joseph.wakeling — 2014-06-08T17:06:13Z
Comment #2 by github-bugzilla — 2014-06-10T12:14:40Z
Commits pushed to master at https://github.com/D-Programming-Language/phoboshttps://github.com/D-Programming-Language/phobos/commit/cb5ee35ad69024293d5d557151e5939065fa0a06
Fix Issue #12877: allow uniform() to handle dchar variates
Since [dchar.min, dchar.max] does not cover the full bit range of dchar,
optimizations that work for other integral types will fail here, and
result in illegal unicode points being generated.
This fix avoids breaking any existing calls to uniform() via a twofold
approach:
* uniform!"[]"(T.min, T.max) will only call uniform!ResultType if
T is not a dchar;
* uniform!dchar will not try and use the entire bit range but will
instead call uniform!"[]"(dchar.min, dchar.max).
Unittests have been added that should prevent such issues from arising
again.
https://github.com/D-Programming-Language/phobos/commit/240a11ebe31ca9980d951553c2dac3fd62070b56
Merge pull request #2235 from WebDrake/uniform-dchar
Fix Issue #12877: allow uniform() to handle dchar variates