[Issue 6362] Can't return const reference to member

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 22 04:07:12 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6362


kennytm at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|Other                       |All
            Version|unspecified                 |D2
         OS/Version|Windows                     |All


--- Comment #1 from kennytm at gmail.com 2011-07-22 04:07:10 PDT ---
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();
}
------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list