www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7606] New: core.time.TickDuration opCmp accepts only lvalues

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

           Summary: core.time.TickDuration opCmp accepts only lvalues
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: matejnanut gmail.com



---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 28 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7606


Alex Rønne Petersen <xtzgzorex gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xtzgzorex gmail.com



13:13:53 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7606


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg gmx.com



PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7606




Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/67a03aa8061595e5e568ca60aacfa52f75bb155a
Updated changelog for issue 7606.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 14 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7606


Jonathan M Davis <jmdavisProg gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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