Thread overview
[Issue 8120] New: std.conv.to throws exception when converting const string to int with -O optimisation switch
May 19, 2012
pabuond@gmail.com
May 19, 2012
pabuond@gmail.com
Nov 28, 2012
Don
Nov 28, 2012
Don
Mar 04, 2013
Don
May 19, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8120

           Summary: std.conv.to throws exception when converting const
                    string to int with -O optimisation switch
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: pabuond@gmail.com


--- Comment #0 from pabuond@gmail.com 2012-05-19 06:28:24 PDT ---
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!

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



--- Comment #1 from pabuond@gmail.com 2012-05-19 06:32:48 PDT ---
Apologies, I had originally simply opened a new thread there instead of properly filing a bug through bugzilla http://forum.dlang.org/thread/ubjqjkvmrcgcyefmwfrs@forum.dlang.org

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.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
           Severity|major                       |critical


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-11-28 08:20:36 PST ---
This sounds like an optimizer bug. Possibly a duplicate of one which has already been fixed.

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



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2012-11-28 08:23:26 PST ---
May be a duplicate of bug 5649

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


monarchdodra@gmail.com changed:

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


--- Comment #4 from monarchdodra@gmail.com 2012-11-28 09:20:38 PST ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 04, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8120


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #5 from Don <clugdbug@yahoo.com.au> 2013-03-04 01:50:49 PST ---
*** This issue has been marked as a duplicate of issue 5649 ***

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