www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21744] New: [REG 2.092.0] NRVO sometimes not performed when

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

          Issue ID: 21744
           Summary: [REG 2.092.0] NRVO sometimes not performed when it
                    should be
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

The following code compiles before v2.092 but fails to compile in v2.092 due to
` disable this(this)`. Digger identifies
https://github.com/dlang/dmd/pull/10885 as the PR that broke it.

---
// Commenting out ` safe:` will make this compile with no other changes.
 safe:

struct S(bool isVeryWeird)
{
     disable this(this);

    static if (isVeryWeird)
    {
        uint notEnum = 2;
        // Changing `maybeEnum` to a non-template function will make
        // this compile with no other changes.
         property uint maybeEnum()()
        {
            // Replacing `return notEnum` with `return 0` will make
            // this compile with no other changes.
            return notEnum;
        }
    }
    else
        enum uint maybeEnum = 0;

    // Removing the following `static if` block will make this compile
    // with no other changes.
    static if (__traits(compiles, { enum e = maybeEnum; }))
    {
        // Empty
    }

     property S spawnAnother()() const
    {
        S result;
        return result;
    }
}

void main()
{
    auto a = S!false.init;
    auto b = a.spawnAnother; // Succeeds.

    auto c = S!true.init;
    auto d = c.spawnAnother; // Compile error.
}
---

--
Mar 21