www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6578] New: Ignored const with struct with constructor

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

           Summary: Ignored const with struct with constructor
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



In DMD 2.055head this compiles and runs with no errors:


struct Foo {
    int x;
    this(int x_) { this.x = x_; }
}
void main() {
    auto f1 = new const(Foo)(1);
    f1.x++;
    auto f2 = new immutable(Foo)(1);
    f2.x++;
    auto f3 = const(Foo)(1);
    f3.x++;
    auto f4 = immutable(Foo)(1);
    f4.x++;
}


While this generates two errors:

struct Foo {
    int x;
}
void main() {
    auto f5 = const(Foo)(1);
    f5.x++; // error
    auto f6 = immutable(Foo)(1);
    f6.x++; // error
}


I think in the first program the f1,f2,f3,f4 structs too need to raise a
compile-time error.

Thanks to Timon Gehr for a suggestion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6578


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|diagnostic                  |patch
                 CC|                            |yebblies gmail.com
           Platform|x86                         |All
         AssignedTo|nobody puremagic.com        |yebblies gmail.com
         OS/Version|Windows                     |All



The devil's patch: https://github.com/D-Programming-Language/dmd/pull/666

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6578




*** Issue 9647 has been marked as a duplicate of this issue. ***

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b133ffbad523c03c11a3253595fb4edf1ccc53b4
Issue 6578 - Wrong type deduction for NewExp and __ctor with struct

Add the constructor's modifiers to the result type, instead of replacing them.

https://github.com/D-Programming-Language/dmd/commit/a319e6d4c70de1fcc28a21b743d3367fb533e116


Issue 6578 - Wrong type deduction for NewExp and __ctor with struct

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




Yet another test case:

struct S {
    this(int[] arr) immutable {}
}
void main() {
    auto s = S([1,2,3]);
    pragma(msg, typeof(s));  // prints immutable(S)
}

Can be fixed by:
https://github.com/D-Programming-Language/dmd/pull/1726

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


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

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




 Yet another test case:
 
 struct S {
     this(int[] arr) immutable {}
 }
 void main() {
     auto s = S([1,2,3]);
     pragma(msg, typeof(s));  // prints immutable(S)
 }
 
 Can be fixed by:
 https://github.com/D-Programming-Language/dmd/pull/1726
Pull-request 1726 is merged, and this issue has been fixed properly. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 26 2013