www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8120] New: std.conv.to throws exception when converting const string to int with -O optimisation switch

reply d-bugmail puremagic.com writes:
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



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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8120




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: -------
May 19 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Nov 28 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8120




May be a duplicate of bug 5649

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


monarchdodra gmail.com changed:

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




 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: -------
Nov 28 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8120


Don <clugdbug yahoo.com.au> changed:

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



*** 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: -------
Mar 04 2013