www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6362] New: Can't return const reference to member

reply d-bugmail puremagic.com writes:
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



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: -------
Jul 22 2011
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 22 2011
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jul 22 2011