www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2788] New: return val not passable via ref const in other method

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2788

           Summary: return val not passable via ref const in other method
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: spam extrawurst.org


This used work perfectly fine, why not anymore ? (since 2.027)

[CODE]
int getVar()
{
        return 2;
}

void foo(ref const int _p)
{}

void main()
{
        foo(getVar());
}
[/CODE]

Error: function main.foo (ref const const(int) _p) does not match parameter
types (int)
Error: getVar() is not an lvalue


-- 
Apr 02 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2788


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de
           Platform|x86                         |All
         OS/Version|Windows                     |All



ref const doesn't make any sense with basic types.

But it makes sense for struct and static array temporaries.

The weird thing is struct literals count as lvalues in D2, so this works:

struct A {}
void foo(ref A a) {}
void main()
{
    foo(A());
}

while calling the following doesn't:
static A bar()
{
    return A();
}

foo(bar());

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