View mode: basic / threaded / horizontal-split · Log in · Help
September 21, 2011
[Issue 6708] New: immutable ref implicit cast to const ref
http://d.puremagic.com/issues/show_bug.cgi?id=6708

          Summary: immutable ref implicit cast to const ref
          Product: D
          Version: D2
         Platform: x86
       OS/Version: Windows
           Status: NEW
         Keywords: rejects-valid
         Severity: normal
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2011-09-21 13:48:10 PDT ---
I think this is correct code because foo and bar can't change the contents of
arr and x in any way:


void foo(const ref int y) {}
void bar(const ref int[5] a1) {}
void spam(const ref int[] a2) {}
void baz(const ref int[int] aa) {}
void main() {
   immutable int x;
   foo(x); // Error?
   immutable int[5] arr1;
   bar(arr1); // Error?
   immutable int[] arr2;
   spam(arr2); // Error?
   immutable int[int] aa;
   baz(aa); // Error?
}


But DMD 2.055 gives errors:

test.d(7): Error: constant 0 is not an lvalue
test.d(9): Error: cast(const(int[5u]))arr1 is not an lvalue
test.d(11): Error: cast(const(int[]))arr2 is not an lvalue
test.d(13): Error: cast(const(int[int]))aa is not an lvalue


See also a thread on this topic in D.learn:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=29609

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 16, 2013
[Issue 6708] immutable ref implicit cast to const ref
http://d.puremagic.com/issues/show_bug.cgi?id=6708


yebblies <yebblies@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
          Keywords|                            |pull
                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> 2013-01-17 01:58:11 EST ---
Only the first one gives an error now.  Happening because the const-folder is
overly aggressive.

https://github.com/D-Programming-Language/dmd/pull/1496

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 16, 2013
[Issue 6708] immutable ref implicit cast to const ref
http://d.puremagic.com/issues/show_bug.cgi?id=6708



--- Comment #2 from yebblies <yebblies@gmail.com> 2013-01-17 02:06:19 EST ---
*** Issue 7225 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: -------
January 18, 2013
[Issue 6708] immutable ref implicit cast to const ref
http://d.puremagic.com/issues/show_bug.cgi?id=6708



--- Comment #3 from github-bugzilla@puremagic.com 2013-01-17 18:45:15 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/704240e0d391cbf76f45d4d5e8e2a87454494e11
Fix Issue 6708 - immutable ref implicit cast to const ref

https://github.com/D-Programming-Language/dmd/commit/685d943a3af777621476239e200d895c6d375490
Merge pull request #1496 from yebblies/issue6708

Fix Issue 6708 - immutable ref implicit cast to const ref

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 18, 2013
[Issue 6708] immutable ref implicit cast to const ref
http://d.puremagic.com/issues/show_bug.cgi?id=6708


Walter Bright <bugzilla@digitalmars.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |RESOLVED
                CC|                            |bugzilla@digitalmars.com
        Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home