DIP 1016--ref T accepts r-values--Formal Assessment

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 31 22:35:26 UTC 2019


On Thu, Jan 31, 2019 at 10:26:39PM +0000, jmh530 via Digitalmars-d-announce wrote:
> On Thursday, 31 January 2019 at 21:57:21 UTC, Steven Schveighoffer wrote:
[...]
> > That being said, you can look at the fact that most people don't
> > even know about this problem, even seasoned veterans, as a sign that
> > it's really not a big problem.
> > 
> 
> The way you put it makes it sound like a bug...
> 
> I don't know if it helps, but below compiles without error.
> 
> struct Foo
> {
>    private int _x;
>    int* x() { return &_x; }
> }
> 
> struct Bar
> {
>    private Foo _y;
>    Foo* y() { return &_y; }
>    void y(Foo foo) { _y = foo; }
> }
> 
> void main() {
>     Foo a = Foo(1);
>     assert(*a.x == 1);
>     *a.x *= 2;
>     assert(*a.x == 2);
> 
>     Bar b;
>     b.y = Foo(1);
>     assert(*b.y.x == 1);
>     *b.y.x *= 2;
>     assert(*b.y.x == 2);
> }

Why is it a problem that this code compiles without error?


T

-- 
Perhaps the most widespread illusion is that if we were in power we would behave very differently from those who now hold it---when, in truth, in order to get power we would have to become very much like them. -- Unknown


More information about the Digitalmars-d-announce mailing list