The problem started with dmd 2.054. I've had no problems with this in earlier versions. struct foo { public: const ref int get() const { return bar[0]; } private: int bar[1]; } void main(){ auto a = foo(); } ==> Error: cast(int)this.bar[0u] is not an lvalue
I believe the previous versions are accept-invalid. The leading 'const' is equivalent to the trailing 'const', which is applying the 'const' to 'this' only. Therefore, the function's type is in fact ref int get() const; If you want to return a const int, apply it directly on the return type. ------------------ struct foo { public: ref const(int) get() const { return bar[0]; } // ^^^^^^^^^^ private: int bar[1]; } void main(){ auto a = foo(); } ------------------
Ah, i see, i guess that seems right. :)