Thread overview
[Issue 8929] New: long.min is a Voldermort literal
Nov 01, 2012
David Eckardt
[Issue 8929] long.min is a Voldemort literal
Nov 02, 2012
Don
Nov 02, 2012
David Eckardt
November 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8929

           Summary: long.min is a Voldermort literal
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: david.eckardt@sociomantic.com


--- Comment #0 from David Eckardt <david.eckardt@sociomantic.com> 2012-11-01 09:23:21 PDT ---
It cannot be named.

static assert (long.min == -9223372036854775807L);
// Error: static assert  (-9223372036854775808L == -9223372036854775807L) is
false

static assert (long.min == -9223372036854775808L); // Error: signed integer overflow

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8929


monarchdodra@gmail.com changed:

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


--- Comment #1 from monarchdodra@gmail.com 2012-11-01 14:27:09 PDT ---
(In reply to comment #0)
> It cannot be named.
> 
> static assert (long.min == -9223372036854775807L);
> // Error: static assert  (-9223372036854775808L == -9223372036854775807L) is
> false
> 
> static assert (long.min == -9223372036854775808L); // Error: signed integer overflow

I don't think this has anything to do with voldermort, and this works just fine:

void main()
{
    long a = -2L^^63;
    assert(a == long.min);
    long b = long.min;
    assert(b == long.min);
}

It sounds more like an interpretation error, whereas *writing* "-9223372036854775808L;" causes an error.

My *guess* is interprets the decimal number into a long, and afterwards, the sign is applied. This chokes in this particular case, because the valid range for longs is [-2^^63, 2^^63-1], so the interpreted number overflows before the compiler has a chance to apply the sign:

long a =  9223372036854775808L; //WRONG
long b = -9223372036854775808L; //LEGAL

But that's just speculation on my part.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8929


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|long.min is a Voldermort    |long.min is a Voldemort
                   |literal                     |literal


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-11-02 03:17:37 PDT ---
(In reply to comment #1)
> (In reply to comment #0)
> > It cannot be named.

> My *guess* is interprets the decimal number into a long, and afterwards, the sign is applied. This chokes in this particular case, because the valid range for longs is [-2^^63, 2^^63-1], so the interpreted number overflows before the compiler has a chance to apply the sign:

Yes, of course that's what's happening. It is a number you cannot write as a literal, you can only use a euphemism like "long.min" or "-2L^^63".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8929



--- Comment #3 from David Eckardt <david.eckardt@sociomantic.com> 2012-11-02 05:16:23 PDT ---
Although no surprise, it might be worth noting that

mixin("static assert(long.min==" ~ long.min.stringof ~ ");");

causes the "signed integer overflow" error, too.

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