www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20613] New: String switch in -betterC fails for 7+ labels

https://issues.dlang.org/show_bug.cgi?id=20613

          Issue ID: 20613
           Summary: String switch in -betterC fails for 7+ labels
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

First reported here:
https://forum.dlang.org/post/ptwcucsmyvjklxagspgb forum.dlang.org

When compiling with -betterC, switches over strings fail with 7 or more cases,
as in this example:

extern(C) void main()
{
    auto s = "F";
    final switch(s)
    {
        case "A": break;
        case "B": break;
        case "C": break;
        case "D": break;
        case "E": break;
        case "F": break;
        case "G": break;
    }
}

Which gives this error message:
dmd2\windows\bin\..\..\src\druntime\import\object.d(2981): Error: TypeInfo
cannot be used with -betterC

The reason can be found on this line: 
https://github.com/dlang/druntime/blob/e018a72084e54ecc7466e97c96e4557b96b7f905/src/core/internal/switch_.d#L67
, which was added in this commit:
https://github.com/dlang/druntime/commit/fa665f6618af7dbc09ed5ba1333f385017b7ece8

Testing indicates the whole anonymous lambda dance used there could be replaced
with
    static immutable cases = [caseLabels];

--
Feb 26