www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15568] New: Wrong contracts generated when compiled with -O

https://issues.dlang.org/show_bug.cgi?id=15568

          Issue ID: 15568
           Summary: Wrong contracts generated when compiled with -O
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dragoscarp gmail.com

The PR https://github.com/D-Programming-Language/dmd/pull/4788 fixing issue
https://issues.dlang.org/show_bug.cgi?id=9383 introduced a regression that can
be reproduced with the following test:

---
import std.algorithm;
import std.array;

class A
{
    B foo(C c, D[] ds, bool f)
    in
    {
        assert(c !is null);
    }
    body
    {
        D[] ds2 = ds.filter!(a => c).array;

        return new B(ds2, f);
    }
}

class B
{
    this(D[], bool)
    {
    }
}

class C
{
}

struct D
{
}

unittest
{
    auto a = new A;
    C c = new C;

    a.foo(c, null, false);
}
---

It runs successfully when it is compiled with:
  dmd -unittest -main
But the contract throws AssertError when compiled with:
  dmd -unittest -main -O

--
Jan 14 2016