[dmd-internals] ref const(T) doesn't accept struct temporaries?

Sean Kelly sean at invisibleduck.org
Fri Dec 10 14:13:13 PST 2010


I'm sure there was a discussion about this.  Why the divergence from C++ here?  I'll change the methods to accept Duration by value--it only contains a long.  "auto ref" is intended to solve a different problem, so I won't be using it here.

On Dec 10, 2010, at 12:28 PM, Andrei Alexandrescu wrote:

> An rvalue should not bind to a reference. I think Duration is small enough to pass by value. If not, we need to wait for "auto ref" to be fixed.
> 
> Andrei
> 
> On 12/10/10 11:51 AM, Sean Kelly wrote:
>> I suppose I should have already known this, but I was surprised today to find that this didn't work:
>> 
>>     auto val = x + seconds(y);
>> 
>>     Duration seconds(long x) { ... }
>> 
>>     struct Duration {
>>         Duration opOpAssign(string op)( ref const(Duration) other ) { ... }
>>     }
>> 
>> With the error:
>> 
>>     Error: function core.time.Duration.opOpAssign!("+").opOpAssign (ref const(Duration) other) is not callable using argument types (Duration)
>>     src/core/sync/config.d(59): Error: seconds(y) is not an lvalue
>> 
>> Someone please tell me that this is a bug and that it will be fixed soon.  A quick search on the bug tracker didn't turn up anything.
>> _______________________________________________
>> dmd-internals mailing list
>> dmd-internals at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/dmd-internals
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals



More information about the dmd-internals mailing list