www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5497] New: Cannot (reinterpret) cast string/array to different array inside CTFs

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

           Summary: Cannot (reinterpret) cast string/array to different
                    array inside CTFs
           Product: D
           Version: 1.057
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: aziz.koeksal gmail.com



PST ---
Example code:

uint[] toArray(string s)
{
  return cast(uint[])s;
}
version(BigEndian)
static assert(toArray("\xdd\xcc\xbb\xaa")[0] == 0xddccbbaa);
else
static assert(toArray("\xdd\xcc\xbb\xaa")[0] == 0xaabbccdd);



// The following code works, of course:
static this()
{
version(BigEndian)
  assert(toArray("\xdd\xcc\xbb\xaa")[0] == 0xddccbbaa);
else
  assert(toArray("\xdd\xcc\xbb\xaa")[0] == 0xaabbccdd);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5497


Don <clugdbug yahoo.com.au> changed:

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



This test case generated wrong code in 2.053 and earlier, but it actually
should have been accepts-invalid.

Since 2.054 it generates

test.d(3): Error: array cast from string to uint[] is not supported at compile
t
ime
test.d(8): Error: cannot evaluate toArray("\xdd\xcc\xbb\xaa") at compile time
test.d(8): Error: static assert  (toArray("\xdd\xcc\xbb\xaa")[0u] ==
-1430532899
u) is not evaluatable at compile time



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

Also the spec now states that such casts are not legal in CTFE.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2011