Bug 9519 – constant bug in structures

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-02-16T06:21:00Z
Last change time
2013-02-17T02:08:21Z
Assigned to
nobody
Creator
magnus_lindberg

Comments

Comment #0 by magnus_lindberg — 2013-02-16T06:21:21Z
Constants & immutables inside structures does not evaluate properly (if you define the same thing outside the structure scope then it works fine). Code demonstrating the bug: http://codepad.org/NxV20KT2 I have not tested if it goes the same on anyother platform. Compiler version: 2.61
Comment #1 by bearophile_hugs — 2013-02-16T06:58:59Z
The code on Codepad: const ConstBug Poo = ConstBug(1, 1, 1); //This works fine struct ConstBug { float X, Y, Z; const ConstBug Test1 = ConstBug(0); //gives (0, NaN, NaN) const ConstBug Test2 = ConstBug(0, 0); //gives (0, 0, NaN) even as there is no such construtor const ConstBug Test3 = ConstBug(1, 1, 1); //should give (2, 2, 2) but gives (1, 1, 1) //const & immutable & static immutable gives all the same result this(float xyz) { X = xyz; Y = xyz; Z = xyz; } this(float x, float y, float z) { X = z * 2; Y = y * 2; Z = z * 2; } }
Comment #2 by rswhite4 — 2013-02-16T07:22:55Z
Works as expected with dmd 2.062 Beta 1.
Comment #3 by andrej.mitrovich — 2013-02-16T11:57:41Z
(In reply to comment #2) > Works as expected with dmd 2.062 Beta 1. Yeah, and this will no longer compile: const ConstBug Test2 = ConstBug(0, 0); What probably happened before is the ctor was never invoked but field initialization was used instead. This is likely a dup report of another bug which was fixed in 2.062.
Comment #4 by k.hara.pg — 2013-02-17T02:08:21Z
*** This issue has been marked as a duplicate of issue 8741 ***