Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public:
return u;
}
/** Forwards member access to contents. */
RefT opDot() { return _p; }
auto opDot() inout { return _p; }

/**
Postblit operator is undefined to prevent the cloning of $(D Unique) objects.
Expand Down Expand Up @@ -288,6 +288,26 @@ private:
assert(!uf2.isEmpty);
}

// ensure Unique behaves correctly through const access paths
@system unittest
{
struct Bar {int val;}
struct Foo
{
Unique!Bar bar = new Bar;
}

Foo foo;
foo.bar.val = 6;
const Foo* ptr = &foo;
static assert(is(typeof(ptr) == const(Foo*)));
static assert(is(typeof(ptr.bar) == const(Unique!Bar)));
static assert(is(typeof(ptr.bar.val) == const(int)));
assert(ptr.bar.val == 6);
foo.bar.val = 7;
assert(ptr.bar.val == 7);
}

// Used in Tuple.toString
private template sharedToString(alias field)
if (is(typeof(field) == shared))
Expand Down