[Issue 5381] New: [regression 2.051] switch fails for wstring and dstring

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 28 00:06:30 PST 2010


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 at invisibleduck.org
        ReportedBy: r.sagitario at gmx.de


--- Comment #0 from Rainer Schuetze <r.sagitario at gmx.de> 2010-12-28 00:04:25 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: -------


More information about the Digitalmars-d-bugs mailing list