Bug 4203 – Const field of struct that contains a whole struct

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-05-18T04:08:00Z
Last change time
2015-06-09T05:11:57Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-05-18T04:08:11Z
I don't understand what's going on here, but even if this is not a bug (and to me it looks like a problem) it's too much tricky for D newbies. This runs with dmd v2.046: // case 1 struct Foo { const Foo f = Foo(); } static assert(Foo.sizeof == 1); void main() {} While this is not OK: // case 2 struct Foo { const Foo f; } static assert(Foo.sizeof == 1); void main() {} dmd v2.046 prints: test.d(2): Error: struct test.Foo cannot have field f with same struct type test.d(2): Error: struct test.Foo cannot have field f with same struct type
Comment #1 by andrej.mitrovich — 2012-12-26T14:27:45Z
This is caused by Issue 3449. The problem is when an initializer is present 'f' becomes a manifest constant. Walter agreed it has to be fixed, but we have to wait for https://github.com/D-Programming-Language/dmd/pull/93 to be merged. *** This issue has been marked as a duplicate of issue 3449 ***