Jump to page: 1 2
Thread overview
[Issue 3167] New: Passing result of a function call as ref argument no longer works
Jul 12, 2009
nfxjfg@gmail.com
Jul 12, 2009
BCS
Jul 12, 2009
Christian Kamm
Aug 06, 2009
Don
Aug 06, 2009
Bill Baxter
Aug 06, 2009
Don
Aug 15, 2009
Walter Bright
Aug 15, 2009
Bill Baxter
Oct 15, 2009
Don
Jan 29, 2010
Walter Bright
Jan 29, 2010
Eldar Insafutdinov
Jan 29, 2010
Walter Bright
Feb 07, 2010
Eldar Insafutdinov
Feb 07, 2010
Don
July 12, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167

           Summary: Passing result of a function call as ref argument no
                    longer works
           Product: D
           Version: 1.046
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: nfxjfg@gmail.com


The following code works with dmd 1.045, but not with 1.046. It seems you can no longer pass the result of a function call as argument to ref parameters.

While it's debatable if the old or new behavior is better, the chan ge breaks existing code.

>>
struct X {
}

X i() {
    return X.init;
}

void foo(ref X x) {
}

void foo() {
    foo(i()); //line 12
}
<<

This fails with
test.d(12): Error: cannot assign to function call

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


BCS <shro8822@vandals.uidaho.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |shro8822@vandals.uidaho.edu




--- Comment #1 from BCS <shro8822@vandals.uidaho.edu>  2009-07-12 09:00:22 PDT ---
I think this is invalid because the error message is totally correct. I expect that this was a bug in older versions.

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


Jarrett Billingsley <jarrett.billingsley@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jarrett.billingsley@gmail.c
                   |                            |om




--- Comment #2 from Jarrett Billingsley <jarrett.billingsley@gmail.com>  2009-07-12 09:44:06 PDT ---
Oh, man.  This breaks so much of MiniD because I use "push(t, MDValue(...))"
all over the place, where MDValue is a struct with a static opCall and push
takes a ref MDValue.

I wonder what bug was fixed that caused this.

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


Christian Kamm <kamm-removethis@incasoftware.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kamm-removethis@incasoftwar
                   |                            |e.de




--- Comment #3 from Christian Kamm <kamm-removethis@incasoftware.de>  2009-07-12 12:35:26 PDT ---
I'm fairly sure this was by design (bug 2621) in D 2.026, but I don't think it was expected to seep through to D1.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au




--- Comment #4 from Don <clugdbug@yahoo.com.au>  2009-08-06 00:08:01 PDT ---
(In reply to comment #3)
> I'm fairly sure this was by design (bug 2621) in D 2.026, but I don't think it was expected to seep through to D1.

It might be related to the fix for bug #2323 ? My patch for that bug was rejected, so I don't know what changes were made.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Bill Baxter <wbaxter@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wbaxter@gmail.com




--- Comment #5 from Bill Baxter <wbaxter@gmail.com>  2009-08-06 06:40:55 PDT ---
(In reply to comment #3)
> I'm fairly sure this was by design (bug 2621) in D 2.026, but I don't think it was expected to seep through to D1.

I hope you're right.
In D2 you can have the ref argument be const (which I hope eliminates the
error), but in D1 you have no such option.  So you often have to resort to
making arguments 'ref' for efficiency even when the function doesn't modify the
argument.

Also the error message could be a little clearer.  Something like "Can't pass a temporary to a function taking a ref argument" would be a lot clearer I think. Passing something to a function taking a ref does not necessarily imply assigning to that ref argument in D1, for the reason stated above.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 06, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167





--- Comment #6 from Don <clugdbug@yahoo.com.au>  2009-08-06 12:24:14 PDT ---
This change is clearly caused by the addition of the new function

Expression *CallExp::modifiableLvalue(Scope *sc, Expression *e)

in expression.c. Comment it out to restore the old behaviour. It doesn't seem to be necessary for any bug fixes -- eg, removing it doesn't reactivate bug 2323.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com




--- Comment #7 from Walter Bright <bugzilla@digitalmars.com>  2009-08-14 22:39:29 PDT ---
What if X is replaced by int? Should that work? I think it's a problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167





--- Comment #8 from Bill Baxter <wbaxter@gmail.com>  2009-08-15 03:38:43 PDT ---
(In reply to comment #7)
> What if X is replaced by int? Should that work? I think it's a problem.

Well, probably not, because 'int' is not a large struct.  So the only reason to pass it 'ref' would be if you wanted to modify it.

But then you get into a case like

X add(X)(ref X a, ref X b) {
    return a + b;
}

where foo takes ref in order to accept large value types without inordinate amounts of copying.  But someone might want to pass int too.  It would be odd if that code worked for certain size arguments but not others.

If you're going to change the D1 behavior anyway, the best solution in my opinion would be to give D1 a way to specify that you want to pass by reference for efficiency, but don't want to modify the value.  Give it a weak form of const parameters like C has.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3167


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |2korden@gmail.com


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2009-10-15 05:27:05 PDT ---
*** Issue 2852 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2