www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7604] New: statically disallow shift amounts provably outside the valid range

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

           Summary: statically disallow shift amounts provably outside the
                    valid range
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timon.gehr gmx.ch



This code is rejected:

void main(){
    int y = 1<<32;
}

But this goes through:

void main(){
    int x;
    int y = 1<<32+(x&1);
}

Since the semantic analysis step already requires the compiler to be able to
compute value ranges, it would make sense to make any shift where the range of
the shift amount does not overlap [0..,31] a compile time error.

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


Ryuichi OHORI <r.97all gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.97all gmail.com



---
In my opinion, if compiler rejects
 int << 32, ulong >> 64, ...,
this also should be a runtime error:

// http://dpaste.dzfl.pl/689920e3
void main()
{
    ulong x = ulong.max;
    foreach (i; 0..64)
    {
        (x >> (64 - i)).writeln();
    }
}

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