[Issue 23083] New: .tupleof on static array rvalue evaluates expression multiple times

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 3 13:39:29 UTC 2022


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

          Issue ID: 23083
           Summary: .tupleof on static array rvalue evaluates expression
                    multiple times
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.100.0-rc.1, the following program causes an AssertError at runtime:

---
int global = 0;

int[2] f()
{
    global++;
    return [123, 456];
}

void g(int a, int b) {}

void main()
{
    g(f().tupleof);
    assert(global == 1);
}
---

The error is:

---
core.exception.AssertError at bug.d(14): 2 != 1
---

This happens because the expression `f().tupleof` is erroneously expanded to
`f()[0].tupleof, f()[1].tupleof`, which results in `f` being called twice
instead of once.

--


More information about the Digitalmars-d-bugs mailing list