www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4491] New: Assigning large const value to ulong type results in "signed integer overflow"

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

           Summary: Assigning large const value to ulong type results in
                    "signed integer overflow"
           Product: D
           Version: D1 & D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ibuclaw ubuntu.com


--- Comment #0 from Iain Buclaw <ibuclaw ubuntu.com> 2010-07-21 13:50:16 PDT ---
The following code:

import std.stdio;
void main()
{
    ulong t;// = 18446744073709551615;
    printf("%llu\n", t.max);
}


Outputs:
18446744073709551615

However, I get a "signed integer overflow" when I try to assign the value
directly.

Code:
import std.stdio;
void main()
{
    ulong t = 18446744073709551615;
    printf("%llu\n", t);
}

Outputs:
bug.d(4): signed integer overflow

Using 'cast(ulong)18446744073709551615' doesn't help either, so I presume this
happens before D knows what datatype the large integer will be assigned to.

IMO, assignments of constant values within the range of foo.min to foo.max
should be allowed for all types.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4491


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-07-21 14:32:06 PDT ---
You need to add an 'L' suffix when it's larger than int.max, and a 'U' suffix
when it's unsigned.

import std.stdio;
void main()
{
    ulong t = 18446744073709551615UL;
    printf("%llu\n", t);
}

The error message should make this clearer. Marking as a 'diagnostic' bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4491


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2010-07-21 14:51:27 PDT ---
What's bad in the compiler/language accepting a line like:

ulong t = 18446744073709551615;

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 21 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4491



--- Comment #3 from Iain Buclaw <ibuclaw ubuntu.com> 2010-07-22 07:48:45 PDT ---
(In reply to comment #1)
 You need to add an 'L' suffix when it's larger than int.max, and a 'U' suffix
 when it's unsigned.
 
 import std.stdio;
 void main()
 {
     ulong t = 18446744073709551615UL;
     printf("%llu\n", t);
 }
 
 The error message should make this clearer. Marking as a 'diagnostic' bug.
I suppose that makes sense once you know. Though it seems that it should more like syntactical sugar to me, rather than a mandatory marking. For example, "1e6" gets translated to 1_000_000. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 22 2010