www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19521] New: safe typesafe_variadic_functions could cause


          Issue ID: 19521
           Summary:  safe typesafe_variadic_functions could cause memory
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: wyrlon gmx.net

The below snippet runs and works fine, but likely only because the compiler
doesn't do the optimisation which the spec explicitly allows.

"An implementation may construct the object or array instance on the stack.
Therefore, it is an error to refer to that instance after the variadic function
has returned"

There are many possible fixes
1) Allow DIP25 style return annotation even if there is no 'ref'.
2) Compilation error
3) Change spec to disallow optimisation

void main()
  auto x1 = fun(1);
  auto x2 = fun(2);

  import std.stdio;
  writeln(x1.a, x2.a);


class C
  int a;
  this(int a) { this.a = a; }

C fun(/* return */ C c...)
    return c;

Dec 29 2018