Phobos is now compiled with -preview=dip1000

H. S. Teoh hsteoh at quickfur.ath.cx
Wed May 15 18:09:01 UTC 2019


On Wed, May 15, 2019 at 12:39:05AM -0700, Walter Bright via Digitalmars-d-announce wrote:
> https://github.com/dlang/phobos/pull/6931
> 
> This is a major milestone in improving the memory safety of D
> programming.  Thanks to everyone who helped with this!
> 
> Time to start compiling your projects with DIP1000, too!

My very first attempt to compile my code with -preview=dip1000 led to a
regression. :-(

Reduced code:
------
import std.container.rbtree;
alias Grid = RedBlackTree!(GridPoint);
struct GridPoint
{
    private string _srcStr;
    int opCmp(in GridPoint p) const { return 0; }
}
------

Compiler output (with -preview=dip1000):
------
/usr/src/d/phobos/std/container/rbtree.d(1111): Error: `@safe` function `std.container.rbtree.RedBlackTree!(GridPoint, "a < b", false).RedBlackTree.toHash` cannot call `@system` function `core.internal.hash.hashOf!(GridPoint).hashOf`
/usr/src/d/druntime/import/core/internal/hash.d(510):        `core.internal.hash.hashOf!(GridPoint).hashOf` is declared here
numid.d(3): Error: template instance `std.container.rbtree.RedBlackTree!(GridPoint, "a < b", false)` error instantiating
------

The culprit is the 'private' in GridPoint.  Removing 'private' gets rid
of the problem.

*Why* putting 'private' on a field member makes toHash unsafe, is beyond
my ability to comprehend.


T

-- 
Windows: the ultimate triumph of marketing over technology. -- Adrian von Bidder


More information about the Digitalmars-d-announce mailing list