Thread overview
BUG? lazy argument + variadic arguments
Jan 07, 2007
Ville Mattila
Jan 07, 2007
Thomas Kuehne
Jan 07, 2007
Ville Mattila
January 07, 2007
Hello,

 I'm very new to d. I'm testing lazy evaluation and it seems like
 I've found bug w/ dmd  compiler on linux. Here are the details.



-- foo.d ---

import std.stdio;
import std.stdarg;
import std.string, std.conv, std.stream;
void foo(lazy void expression, ...)
{
  //expression();
  if (_arguments.length > 0) {
    _arguments[0].print();
    //writefln("got vararg:" ~ _arguments[0].name);
    if ((_arguments[0]) == typeid(char[])) {
      writefln("got vararg:" ~ std.conv.toString(_arguments.length));
      char[] tmp_msg = va_arg!(char[])(_argptr);
      writefln("GOOTT vararg: " ~ tmp_msg);

    }
  }
}

int main(char[][] args)
{
  foo(writefln("barz"),"foo");
  return(0);
}

--- foo.d ----

./foo
char[]
got vararg:1
Segmentation fault (core dumped)
mulperi@mulperi-desktop:/usr/local/src/apps/d/dmd/samples/d$ dmd --help
Digital Mars D Compiler v1.0
Copyright (c) 1999-2007 by Digital Mars written by Walter Bright
Documentation: www.digitalmars.com/d/index.html
Usage:
  dmd files.d ... { -switch }

I'm usring xubuntu 6.10 w/ latest patches.

 - Ville
January 07, 2007
Ville Mattila schrieb am 2007-01-07:
> Hello,
>
>   I'm very new to d. I'm testing lazy evaluation and it seems like
>   I've found bug w/ dmd  compiler on linux. Here are the details.
>
>
>
> -- foo.d ---
>
> import std.stdio;
> import std.stdarg;
> import std.string, std.conv, std.stream;
> void foo(lazy void expression, ...)
> {
>    //expression();
>    if (_arguments.length > 0) {
>      _arguments[0].print();
>      //writefln("got vararg:" ~ _arguments[0].name);
>      if ((_arguments[0]) == typeid(char[])) {
>        writefln("got vararg:" ~ std.conv.toString(_arguments.length));
>        char[] tmp_msg = va_arg!(char[])(_argptr);
>        writefln("GOOTT vararg: " ~ tmp_msg);
>
>      }
>    }
> }
>
> int main(char[][] args)
> {
>    foo(writefln("barz"),"foo");
>    return(0);
> }
>
> --- foo.d ----
>
> ./foo
> char[]
> got vararg:1
> Segmentation fault (core dumped)
> mulperi@mulperi-desktop:/usr/local/src/apps/d/dmd/samples/d$ dmd --help
> Digital Mars D Compiler v1.0
> Copyright (c) 1999-2007 by Digital Mars written by Walter Bright
> Documentation: www.digitalmars.com/d/index.html
> Usage:
>    dmd files.d ... { -switch }
>
> I'm usring xubuntu 6.10 w/ latest patches.

The "lazy void expression" causes the problem. I'm unsure if "lazy void" is legal, but it certanly causes an incorrect code generation.

Please file this bug at:
http://d.puremagic.com/issues/

Thomas


January 07, 2007
> 
> The "lazy void expression" causes the problem. I'm unsure if
> "lazy void" is legal, but it certanly causes an incorrect code
> generation.
> 
> Please file this bug at:
> http://d.puremagic.com/issues/
> 

 The bug 814 has been filled.

 - Ville