Bug 12760 – Initializing an object that has "this(Args) inout" causes "discards return value" warning
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-18T02:12:00Z
Last change time
2014-05-25T23:55:27Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
sinkuupump
Comments
Comment #0 by sinkuupump — 2014-05-18T02:12:49Z
```
import std.typecons : Nullable;
class C
{
Nullable!int nullable;
this()
{
nullable = 0; // Warning: calling std.typecons.Nullable!int.Nullable.this without side effects discards return value of type Nullable!int, prepend a cast(void) if intentional
}
}
void main()
{
Nullable!int n;
n = 0; // ok
}
```
Comment #1 by monarchdodra — 2014-05-18T07:09:12Z
(In reply to sinkuu from comment #0)
> this()
> {
> nullable = 0; // Warning: calling
> ...
> Nullable!int n;
> n = 0; // ok
I'll point out that these are not the same: The first actually calls a constructor, whereas the second calls opAssign.
In any case, here is a reduced test case:
struct S(T)
{
T i;
this(T j) inout //<-- HERE
{ }
}
struct K
{
S!int nullable;
this(int)
{
nullable = 0;
//Or nullable = S!int(0);
}
}
The issue is the "this" is marked as inout. I'm not quite sure what that (currently) means, but it's what is triggering the issue.
Re tagging as DMD regressions.
Comment #2 by dlang-bugzilla — 2014-05-21T02:37:07Z