D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22134 - Deprecate returning a discarded void value from a function
Summary: Deprecate returning a discarded void value from a function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-07-21 09:07 UTC by Iain Buclaw
Modified: 2022-07-07 06:19 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2021-07-21 09:07:28 UTC
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
---
Comment 1 Iain Buclaw 2021-07-21 09:09:02 UTC
To be clear, this is only about void values with no side effects.  This is already done with ExpStatement and CommaExp with the use of the `discardValue`.
Comment 2 Dlang Bot 2021-07-21 09:26:33 UTC
@ibuclaw created dlang/dmd pull request #12898 "fix Issue 22134 - Deprecate returning a void value from a function" fixing this issue:

- fix Issue 22134 - Deprecate returning a void value from a function

https://github.com/dlang/dmd/pull/12898
Comment 3 Dlang Bot 2022-07-07 06:19:12 UTC
dlang/dmd pull request #12898 "fix Issue 22134 - Deprecate returning a discarded void value from a function" was merged into master:

- d6a07ccd0a2ab6ec757d54b40b5b0697a9d54144 by Iain Buclaw:
  fix Issue 22134 - Deprecate returning a discarded void value from a function

https://github.com/dlang/dmd/pull/12898