www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5381] New: [regression 2.051] switch fails for wstring and dstring

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

           Summary: [regression 2.051] switch fails for wstring and
                    dstring
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: patch, wrong-code
          Severity: regression
          Priority: P2
         Component: druntime
        AssignedTo: sean invisibleduck.org
        ReportedBy: r.sagitario gmx.de



PST ---
With dmd 2.051, switch statement on strings other than utf8 may fail:

import std.stdio;

int testswitch(wstring ws)
{
    switch(ws)
    {
    case "unittest":        return -1;
    case "D_Version2":      return 1;
    case "none":            return -1;
    case "all":             return 1;
    default:                return 0;
    }
}

void main()
{
    wstring ws = "none";
    writeln("testswitch = ", testswitch(ws));
}

outputs 0, but -1 is expected.

Here's the patch, that just copies the corresponding line for the string
switches into the implementation for wstring and dstring:

Index: switch_.d
===================================================================
--- switch_.d    (revision 455)
+++ switch_.d    (working copy)
   -241,7 +241,7   
     {
         auto mid = (low + high) >> 1;
         auto pca = table[mid];
-        auto c = ca.length - pca.length;
+        auto c   = cast(sizediff_t)(ca.length - pca.length);
         if (c == 0)
         {
             c = memcmp(ca.ptr, pca.ptr, ca.length * wchar.sizeof);
   -353,7 +353,7   
     {
         auto mid = (low + high) >> 1;
         auto pca = table[mid];
-        auto c = ca.length - pca.length;
+        auto c   = cast(sizediff_t)(ca.length - pca.length);
         if (c == 0)
         {
             c = memcmp(ca.ptr, pca.ptr, ca.length * dchar.sizeof);

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


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |braddr puremagic.com
         Resolution|                            |FIXED
         AssignedTo|sean invisibleduck.org      |braddr puremagic.com



---
Fix in http://dsource.org/projects/druntime/changeset/460

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