www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9519] New: constant bug in structures

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9519

           Summary: constant bug in structures
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: magnus_lindberg live.se


--- Comment #0 from magnus_lindberg live.se 2013-02-16 06:21:21 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 16 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9519


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2013-02-16 06:58:59 PST ---
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;
     }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9519


rswhite4 googlemail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rswhite4 googlemail.com


--- Comment #2 from rswhite4 googlemail.com 2013-02-16 07:22:55 PST ---
Works as expected with dmd 2.062 Beta 1.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9519


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-02-16
11:57:41 PST ---
(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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 16 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9519


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-02-17 02:08:21 PST ---
*** This issue has been marked as a duplicate of issue 8741 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 17 2013