Bug 7606 – core.time.TickDuration opCmp accepts only lvalues
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-28T13:11:00Z
Last change time
2012-03-14T00:38:51Z
Assigned to
nobody
Creator
matejnanut
Comments
Comment #0 by matejnanut — 2012-02-28T13:11:53Z
Code snippet:
import core.time: TickDuration;
import std.datetime: StopWatch, AutoStart;
void main()
{
auto wait = TickDuration.from!`msecs`(1000);
auto timer = StopWatch(AutoStart.yes);
while (timer.peek < wait) // Okay.
{ }
while (wait >= timer.peek) // Compile error.
{ }
}
Compiler output:
comparison.d(13): Error: function core.time.TickDuration.opCmp (ref const(TickDuration) rhs) const is not callable using argument types (TickDuration)
comparison.d(13): Error: timer.peek() is not an lvalue
I assume the same thing happens elsewhere in the library. As D strives to be an intuitive language, I reason this to be a bug. "<" and ">=" should work identically in this circumstance.
Comment #1 by alex — 2012-02-28T13:13:53Z
What's happening here is that TickDuration's opCmp takes a 'ref' value. This is exactly the reason I *always* avoid ref on op*(), because it creates annoying situations like this one (in fact, I ran into this today as well).
I don't know if auto ref would fix this.
Comment #2 by issues.dlang — 2012-02-28T14:13:21Z
There's no really no reason for opCmp to take anything other than a straight TickDuration in this case. TickDuration holds 1 long and that's it. It's not particularly large or complicated.
In the general case, using auto ref would probably be the correct solution, but auto ref doesn't currently work for non-templated functions, which opCmp obviously isn't.
Comment #3 by github-bugzilla — 2012-03-14T00:26:42Z