digitalmars.D.bugs - [Issue 7834] New: Assign x%int to int without cast?
- d-bugmail puremagic.com (31/31) Apr 05 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (12/12) Apr 11 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (12/13) Apr 21 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (7/12) Apr 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (7/7) Apr 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (8/10) Apr 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (18/30) Apr 23 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
- d-bugmail puremagic.com (13/19) Apr 24 2012 http://d.puremagic.com/issues/show_bug.cgi?id=7834
http://d.puremagic.com/issues/show_bug.cgi?id=7834 Summary: Assign x%int to int without cast? Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc --- Comment #0 from bearophile_hugs eml.cc 2012-04-05 17:35:56 PDT --- In DMD 2.059beta this code compiles with no warnings or errors: void main(string[] args) { uint x; ubyte y = cast(ubyte)args.length; ubyte z = x % y; } So I'd like code similar to this too to compile with no need of a cast: void main() { ulong x; int y; int z = x % y; } Currently it gives: test.d(4): Error: cannot implicitly convert expression (x % cast(ulong)y) of type ulong to int -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 05 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Assign x%int to int without |Assign x%int to int without |cast? |cast Severity|enhancement |normal --- Comment #1 from bearophile_hugs eml.cc 2012-04-11 16:02:44 PDT --- Now I think this is supposed to work, so it's not an enhancement request. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 11 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 SomeDude <lovelydear mailmetrash.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lovelydear mailmetrash.com --- Comment #2 from SomeDude <lovelydear mailmetrash.com> 2012-04-21 10:25:02 PDT --- (In reply to comment #1)Now I think this is supposed to work, so it's not an enhancement request.I don't see where in the spec ulong can be promoted to int. http://dlang.org/type.html -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 21 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 --- Comment #3 from bearophile_hugs eml.cc 2012-04-22 03:35:15 PDT --- (In reply to comment #2)(In reply to comment #1)Thank you, then I think the spec too need to be fixed. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------Now I think this is supposed to work, so it's not an enhancement request.I don't see where in the spec ulong can be promoted to int. http://dlang.org/type.html
Apr 22 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 --- Comment #4 from SomeDude <lovelydear mailmetrash.com> 2012-04-22 10:43:27 PDT --- That doesn't make any sense. You can't promote a 64 bit unsigned type into a 32 bit signed type. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 22 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 --- Comment #5 from bearophile_hugs eml.cc 2012-04-22 11:57:20 PDT --- (In reply to comment #4)That doesn't make any sense. You can't promote a 64 bit unsigned type into a 32 bit signed type.Give me some time to think some more about it, I have a backlog of bugs to take a look at (thanks to your recent efforts). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 22 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |clugdbug yahoo.com.au Resolution| |INVALID --- Comment #6 from Don <clugdbug yahoo.com.au> 2012-04-23 03:23:44 PDT --- (In reply to comment #0)In DMD 2.059beta this code compiles with no warnings or errors: void main(string[] args) { uint x; ubyte y = cast(ubyte)args.length; ubyte z = x % y; }So I'd like code similar to this too to compile with no need of a cast: void main() { ulong x; int y; int z = x % y; }These two bits of code aren't analogous. If y was -1, when cast to ulong it becomes 0xFFFF_FFFF_FFFF_FFFF Therefore, x % y could be 0.. ulong.max; there's no way that can fit into an int. The compiler is correct. OTOH if you change int -> uint, it works. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 23 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7834 --- Comment #7 from bearophile_hugs eml.cc 2012-04-24 19:39:48 PDT --- (In reply to comment #6)These two bits of code aren't analogous. If y was -1, when cast to ulong it becomes 0xFFFF_FFFF_FFFF_FFFF Therefore, x % y could be 0.. ulong.max; there's no way that can fit into an int. The compiler is correct.You are of course right, thank you Don and sorry SomeDude.OTOH if you change int -> uint, it works.Right, this compiles: void main() { ulong x; uint y = 1; int z = x % y; } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 24 2012