www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4521] New: accepts-invalid Array-wise assignment on unallocated array is accepted

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

           Summary: accepts-invalid Array-wise assignment on unallocated
                    array is accepted
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



11:46:44 PDT ---
The following code should raise an out of bounds error:

import std.stdio;

void main() {
   double[] c;
   c[] = 4;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 27 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521


nfxjfg gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg gmail.com



Maybe I'm missing something, but no it should not.
"c[] = 4;" just sets every array element to 4, and it works even if there are 0
array elements.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
                 CC|                            |clugdbug yahoo.com.au
            Summary|accepts-invalid Array-wise  |Array-wise assignment on
                   |assignment on unallocated   |unallocated array is
                   |array is accepted           |accepted




 Maybe I'm missing something, but no it should not.
 "c[] = 4;" just sets every array element to 4, and it works even if there are 0
 array elements.
Yes. Some related situations are definitely bugs though. Perhaps this one should be marked as a duplicate of bug 2547. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521


bearophile_hugs eml.cc changed:

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



This is not a bug, I think this can be closed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521




05:55:29 PDT ---
But isn't there a difference between arrays that had all of their elements
removed and arrays that have not yet been allocated in the first place? 

I filed it since Walter seems to have confirmed this:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=114041

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521




06:38:07 PDT ---
Actually I think I'm confusing myself with how dynamic allocation works. I
thought the dynamic array always have to be called with new, but it appears I
can change the length of an array without calling new in the first place, e.g.:

    int[] a;
    a.length = 4;
    a[] = 4;
    writeln(a);   // writes 4 4 4 4

So this should probably get closed. Sorry for the confusion.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4521


bearophile_hugs eml.cc changed:

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


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2010