Bug 8120 – std.conv.to throws exception when converting const string to int with -O optimisation switch

Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-19T06:28:00Z
Last change time
2013-03-04T01:50:49Z
Keywords
wrong-code
Assigned to
nobody
Creator
pabuond

Comments

Comment #0 by pabuond — 2012-05-19T06:28:24Z
Hi, It seems code compiled by dmd with or without the optimisation switch -O behaves differently in this situation: -------------------------------------------- /* * Compile with either * dmd main.d (won't throw exception) * or * dmd main.d -O (will throw exception) */ import std.conv; void main() { string a = "1"; const string b = "10"; int Na = to!int(a); // fine int Nb = to!int(b); // throws exception if compiled with -O const int constNb = to!int(b); // throws exception if compiled with -O } -------------------------------------------- A problem only occurs with the optimisation switch (-O), in which case an exception is thrown upon conversion of the const string to int (or uint; perhaps others too?). The exception thrown is: std.conv.ConvException@/usr/local/bin/../include/dmd2/phobos/std/conv.d(1749): Can't convert value `10' of type string to type int ---------------- 5 main 0x000b630e int std.conv.toImpl!(int, const(immutable(char)[])).toImpl(const(immutable(char)[])) + 110 6 main 0x000b6239 int std.conv.to!(int).to!(const(immutable(char)[])).to(const(immutable(char)[])) + 17 7 main 0x000b5da4 _Dmain + 64 8 main 0x000c3ff3 extern (C) int rt.dmain2.main(int, char**).void runMain() + 23 9 main 0x000c3b9d extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 29 10 main 0x000c4040 extern (C) int rt.dmain2.main(int, char**).void runAll() + 64 11 main 0x000c3b9d extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 29 12 main 0x000c3b37 main + 179 13 main 0x000b5d59 start + 53 14 ??? 0x00000001 0x0 + 1 ---------------- Thanks!
Comment #1 by pabuond — 2012-05-19T06:32:48Z
Apologies, I had originally simply opened a new thread there instead of properly filing a bug through bugzilla http://forum.dlang.org/thread/[email protected] I said 'major' because may occur by converting integers given on the command line as string (within the program, these arguments are const, so a copy of it might be a const string though perhaps bad style?). And I would always use -O -release for a public release of my program.
Comment #2 by clugdbug — 2012-11-28T08:20:36Z
This sounds like an optimizer bug. Possibly a duplicate of one which has already been fixed.
Comment #3 by clugdbug — 2012-11-28T08:23:26Z
May be a duplicate of bug 5649
Comment #4 by monarchdodra — 2012-11-28T09:20:38Z
(In reply to comment #2) > This sounds like an optimizer bug. Possibly a duplicate of one which has > already been fixed. FWIW, I can replicate this issue on my win7x64 with 2.055. It runs as expected with 2.058, 2.060 and 2.061alpha. Sounds like it is fixed.
Comment #5 by clugdbug — 2013-03-04T01:50:49Z
*** This issue has been marked as a duplicate of issue 5649 ***