Bug 7369 – Inout constructor causes compiler to reject invariant

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-01-25T18:29:00Z
Last change time
2012-01-29T14:33:39Z
Keywords
rejects-valid
Assigned to
nobody
Creator
smjg

Comments

Comment #0 by smjg — 2012-01-25T18:29:24Z
struct TestStruct { invariant() {} this(int data) inout {} } ---------- bad_invariant.d(2): Error: function bad_invariant.TestStruct.__invariant () is not callable using argument types () ---------- (DMD 2.057 Win32) Removing the constructor removes the error. Changing the struct to a class makes no difference.
Comment #1 by yebblies — 2012-01-27T20:10:45Z
Well, what should happen? You can't call a non-const invariant from a const function (or immutable or inout). The same issue exists with shared constructors. If anyone has a solution, we can use it to solve issue 519 as well.
Comment #2 by smjg — 2012-01-28T01:08:56Z
invariant() const {} doesn't compile. Though I've just found that const invariant() {} does. But why aren't invariants automatically const?
Comment #3 by yebblies — 2012-01-28T02:16:20Z
(In reply to comment #2) > invariant() const {} > doesn't compile. Though I've just found that > const invariant() {} > does. > That's looks like another bug. Would you like to file it? > But why aren't invariants automatically const? Probably the same reason in and out contracts aren't const... but at least there's a trivial workaround.
Comment #4 by github-bugzilla — 2012-01-29T14:16:12Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3c138718365541cde67abbdcfc031d755c3a7969 fix Issue 7369 - Inout constructor causes compiler to reject invariant