[Issue 22134] New: Deprecate returning a void value from a function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 21 09:07:28 UTC 2021


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

          Issue ID: 22134
           Summary: Deprecate returning a void value from a function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ibuclaw at gdcproject.org

For example: libdparse has an opIndex returning the value of a `void[]`.

https://github.com/dlang-community/libdparse/blob/fbdf71b929a9f9bc982d0204f921371806e5d412/src/dparse/stack_buffer.d#L73-L82

---
struct StackBuffer
{
    auto opIndex(size_t i)
    {
        return arr[i];
    }

private:
    void[] arr;
}
---

This is clearly a dead function, as any use of it will result in the error:
---
Error: variable `var` type void is inferred from initializer
`buf.opIndex(0LU)`, and variables cannot be of type void
Error: expression buf.opIndex(0LU) is void and has no value
---

--


More information about the Digitalmars-d-bugs mailing list