www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - std.conv.to throws exception when converting const string to int with

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!
May 18 2012