Thread overview
Mysterious char[] bug (dmd 0.125)
May 29, 2005
zwang
Jun 04, 2005
Thomas Kühne
Jun 05, 2005
zwang
Jun 05, 2005
Dave
Jun 11, 2005
Thomas Kühne
Jun 16, 2005
Walter
Jun 16, 2005
zwang
May 29, 2005
<code>
import std.stdio;
const char[] culprit;//#2
void f(...){	
    char[] s;
    void putc(dchar c){
        std.utf.encode(s, c);
    }
    std.format.doFormat(&putc, _arguments, _argptr);	
    //foreach(char ch; s){} //#9
    writef(s);
}
void main(){
    f("mystery");
}

</code>

The program above does not display "mystery" as expected.
The string can be displayed when line #2 is removed
or when line #9 is uncommented, both seemingly irrelevant.

I've smelt something fishy in dmd's code generator.
June 04, 2005
zwang wrote:

> <code>
> import std.stdio;
> const char[] culprit;//#2
> void f(...){
>     char[] s;
>     void putc(dchar c){
>         std.utf.encode(s, c);
>     }
>     std.format.doFormat(&putc, _arguments, _argptr);
>     //foreach(char ch; s){} //#9
>     writef(s);
> }
> void main(){
>     f("mystery");
> }
>
> </code>
>
> The program above does not display "mystery" as expected.
> The string can be displayed when line #2 is removed
> or when line #9 is uncommented, both seemingly irrelevant.
>
> I've smelt something fishy in dmd's code generator.

Can you reproduce this bug without using Phobo's functions?

Thomas



June 05, 2005
Thomas Kühne wrote:
> zwang wrote:
> 
>> <code>
>> import std.stdio;
>> const char[] culprit;//#2
>> void f(...){
>>     char[] s;
>>     void putc(dchar c){
>>         std.utf.encode(s, c);
>>     }
>>     std.format.doFormat(&putc, _arguments, _argptr);
>>     //foreach(char ch; s){} //#9
>>     writef(s);
>> }
>> void main(){
>>     f("mystery");
>> }
>>
>> </code>
>>
>> The program above does not display "mystery" as expected.
>> The string can be displayed when line #2 is removed
>> or when line #9 is uncommented, both seemingly irrelevant.
>>
>> I've smelt something fishy in dmd's code generator.
> 
> 
> Can you reproduce this bug without using Phobo's functions?
> 
> Thomas
> 

I can reproduce the bug without calling std.utf.encode:
<code>
import std.stdio;
const char[] culprit;//#2
void f(...){
    char[] s;
    void putc(dchar c){
	s ~= c;		
    }
    std.format.doFormat(&putc, _arguments, _argptr);
    //foreach(char ch; s){} //#9
    writef(s);
}
void main(){
    f("mystery");
}
</code>
June 05, 2005
In article <d7tlh1$j0c$1@digitaldaemon.com>, zwang says...
>
>Thomas Kühne wrote:
>> 
>> Can you reproduce this bug without using Phobo's functions?
>> 
>> Thomas
>> 
>
>I can reproduce the bug without calling std.utf.encode:
><code>
>import std.stdio;
>const char[] culprit;//#2
>void f(...){
>     char[] s;
>     void putc(dchar c){
>	s ~= c;
>     }
>     std.format.doFormat(&putc, _arguments, _argptr);
>     //foreach(char ch; s){} //#9
>     writef(s);
>}
>void main(){
>     f("mystery");
>}
></code>

Also, compiling w/ -O gives the expected output (both Linux and Win32).

- Dave


June 11, 2005
zwang wrote:

> <code>
> import std.stdio;
> const char[] culprit;//#2
> void f(...){
>     char[] s;
>     void putc(dchar c){
>         std.utf.encode(s, c);
>     }
>     std.format.doFormat(&putc, _arguments, _argptr);
>     //foreach(char ch; s){} //#9
>     writef(s);
> }
> void main(){
>     f("mystery");
> }
>
> </code>
>
> The program above does not display "mystery" as expected.
> The string can be displayed when line #2 is removed
> or when line #9 is uncommented, both seemingly irrelevant.
>
> I've smelt something fishy in dmd's code generator.

Added to DStress as http://dstress.kuehne.cn/run/o/odd_bug_03_A.d http://dstress.kuehne.cn/run/o/odd_bug_03_B.d http://dstress.kuehne.cn/run/o/odd_bug_03_C.d

Thomas


June 16, 2005
"zwang" <nehzgnaw@gmail.com> wrote in message news:d7d2kq$1mc$1@digitaldaemon.com...
> The program above does not display "mystery" as expected.

It's already been reported and the fix will go out in the next update.


June 16, 2005
Walter wrote:
> "zwang" <nehzgnaw@gmail.com> wrote in message
> news:d7d2kq$1mc$1@digitaldaemon.com...
> 
>>The program above does not display "mystery" as expected.
> 
> 
> It's already been reported and the fix will go out in the next update.
> 
> 

Great! I'm wondering where the bug lurks.