Bug 22134 – Deprecate returning a discarded void value from a function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-07-21T09:07:28Z
Last change time
2022-07-07T06:19:12Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-07-21T09:07:28Z
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 by ibuclaw — 2021-07-21T09:09:02Z
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 by dlang-bot — 2021-07-21T09:26:33Z
@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 by dlang-bot — 2022-07-07T06:19:12Z
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