Thread overview
[Issue 6578] New: Ignored const with struct with constructor
Jan 31, 2012
yebblies
Mar 05, 2013
yebblies
Mar 07, 2013
Kenji Hara
Apr 26, 2013
Kenji Hara
August 30, 2011
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


--- Comment #0 from bearophile_hugs@eml.cc 2011-08-30 04:57:48 PDT ---
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: -------
January 31, 2012
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


--- Comment #1 from yebblies <yebblies@gmail.com> 2012-01-31 17:26:17 EST ---
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: -------
March 05, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6578



--- Comment #2 from yebblies <yebblies@gmail.com> 2013-03-06 02:25:03 EST ---
*** 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: -------
March 06, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6578



--- Comment #3 from github-bugzilla@puremagic.com 2013-03-06 00:44:46 PST ---
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 Merge pull request #666 from yebblies/issue6578

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: -------
March 07, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=6578



--- Comment #4 from Kenji Hara <k.hara.pg@gmail.com> 2013-03-06 23:11:53 PST ---
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: -------
April 26, 2013
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


--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2013-04-26 04:16:29 PDT ---
(In reply to comment #4)
> 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: -------