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
Comment #3 by k.hara.pg — 2014-05-22T02:24:48Z
Comment #4 by github-bugzilla — 2014-05-25T23:55:27Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3f3f8cfb49f381e81d3b868cbcaa9bc91ec10d4b fix Issue 12760 - Initializing an object that has "this(Args) inout" causes "discards return value" warning https://github.com/D-Programming-Language/dmd/commit/f4ef69f504db74cd0debaa3aadd5f469440c3013 Merge pull request #3569 from 9rnsr/fix12760 [REG2.066a] Issue 12760 - Initializing an object that has "this(Args) inout" causes "discards return value" warning