www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1199] New: Strange error messages when indexing empty arrays or strings at compile time

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

           Summary: Strange error messages when indexing empty arrays or
                    strings at compile time
           Product: D
           Version: 1.011
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: trivial
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: deewiant gmail.com


// Error: non-constant expression [][__dollar - 1u]
char a = (cast(char[])[])[$-1];

Using an immediate value like 0 in place of $-1 gives the sensible message
explaining that the index is out of bounds.

// Error: string index 4294967295 is out of bounds [0 .. 17540474638172160]
char b = ""[$-1];

Doesn't help here, though:

// Error: string index 0 is out of bounds [0 .. 17540474638172160]
char c = ""[0];

// Ditto
char d = ""[$];


-- 
Apr 28 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199


bugzilla digitalmars.com changed:

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




------- Comment #1 from bugzilla digitalmars.com  2007-07-01 13:29 -------
Fixed DMD 1.018 and DMD 2.002


-- 
Jul 01 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199


deewiant gmail.com changed:

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




------- Comment #2 from deewiant gmail.com  2007-07-02 07:33 -------
The latter two cases still claim that 0 is out of bounds of 0..(big number)
(should be 0..0), and in all four cases the error message is output twice.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199


bugzilla digitalmars.com changed:

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




------- Comment #3 from bugzilla digitalmars.com  2007-07-02 12:03 -------
1) 0 is out of bounds in an array of length 0. You cannot access the first
element of a 0 length array, and [0] accesses the first element.

2) The big number is -1 as a size_t. Array indices are implicitly converted to
size_t.

3) Cascaded error messages are often not very helpful, but they aren't bugs in
the compiler.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199





------- Comment #4 from deewiant gmail.com  2007-07-02 14:01 -------
My point was: why do ""[0] and ""[$] generate an error talking about 0 out of
bounds of [0 .. 43730463654674432] instead of [0 .. 0]? And that number
definitely isn't cast(size_t)-1, it doesn't even fit in a 32-bit integer.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199





------- Comment #5 from bugzilla digitalmars.com  2007-07-02 15:20 -------
For the last 2 cases, I get:

test2.d(2): Error: string index 0 is out of bounds [0 .. 0]
test2.d(2): Error: string index 0 is out of bounds [0 .. 0]
test2.d(5): Error: string index 0 is out of bounds [0 .. 0]
test2.d(5): Error: string index 0 is out of bounds [0 .. 0]

which, while redundant, is correct.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199


deewiant gmail.com changed:

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




------- Comment #6 from deewiant gmail.com  2007-07-02 22:57 -------
I'm running 1.018 and get:

asdf.d(2): Error: string index 0 is out of bounds [0 .. 43730721352712192]
asdf.d(2): Error: string index 0 is out of bounds [0 .. 43730721352712192]
asdf.d(5): Error: string index 0 is out of bounds [0 .. 43730721352712192]
asdf.d(5): Error: string index 0 is out of bounds [0 .. 43730721352712192]

With -inline or -release thrown, it's 43730772892319744 instead, and with both
thrown it's 43730824431927296.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199





------- Comment #7 from bugzilla digitalmars.com  2007-07-02 23:18 -------
Please post exactly what the source file you're running is and the switches
used.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199





------- Comment #8 from deewiant gmail.com  2007-07-02 23:28 -------
Same as the original:

char c = ""[0];
char d = ""[$];

"dmd asdf" leads to the errors I mentioned. "dmd asdf -inline", "dmd asdf
-release", and "dmd asdf -inline -release" change the ending index in the error
message.


-- 
Jul 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199





------- Comment #9 from onlystupidspamhere yahoo.se  2007-07-03 02:08 -------
(In reply to comment #8)
 char c = ""[0];
 char d = ""[$];
 
 "dmd asdf" leads to the errors I mentioned. "dmd asdf -inline", "dmd asdf
 -release", and "dmd asdf -inline -release" change the ending index in the
 error message.

I can confirm this. I'm using DMD 1.018 and latest Tango on Linux. Here's the output of dmd -v -c b1199.d: parse b1199 semantic b1199 import object (/home/jm/d/tango/object.di) semantic2 b1199 b1199.d(1): Error: string index 0 is out of bounds [0 .. 582418249900097536] b1199.d(1): Error: string index 0 is out of bounds [0 .. 582419830448062464] b1199.d(2): Error: string index 0 is out of bounds [0 .. 582418249900097536] b1199.d(2): Error: string index 0 is out of bounds [0 .. 582421617154457600] --
Jul 03 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1199


bugzilla digitalmars.com changed:

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




------- Comment #10 from bugzilla digitalmars.com  2007-07-30 15:54 -------
Fixed DMD 1.019 and 2.003


-- 
Jul 30 2007