Thread overview
[Issue 6362] New: Can't return const reference to member
Jul 22, 2011
Pierre
Jul 22, 2011
kennytm@gmail.com
Jul 22, 2011
Pierre LeMoine
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6362

           Summary: Can't return const reference to member
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: yarrluben+dbugs@googlemail.com


--- Comment #0 from Pierre <yarrluben+dbugs@googlemail.com> 2011-07-22 03:57:48 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6362


kennytm@gmail.com changed:

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


--- Comment #1 from kennytm@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: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6362


Pierre LeMoine <yarrluben+dbugs@googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Pierre LeMoine <yarrluben+dbugs@googlemail.com> 2011-07-22 04:25:30 PDT ---
Ah, i see, i guess that seems right. :)

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