www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21071] New: Undefined reference error when converting strings


          Issue ID: 21071
           Summary: Undefined reference error when converting strings to
                    enums in static switch.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: link-failure
          Severity: regression
          Priority: P2
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: nomad cornercase.gr

When I try to convert a string to an enumeration using "to!MyEnum" inside the
switch header, I'm getting an undefined reference error from the linker when I
attempt to compile in debug mode with dmd.

Suppose I have a `main.d` file like the following:

    import std.string /*required to reproduce error*/, std.conv;

    void main()
        enum Foo {bar}

        // Just `to!Foo` or just `final switch` aren't 
        // enough to reproduce the error
        final switch(to!Foo("bar"))
        case Foo.bar:

and I attempt to compile using `dmd -debug main.d`. I'd expect compilation to
finish successfully, but instead I'm getting:

    main.o: In function `_Dmain':
    main.d:(.text._Dmain[_Dmain]+0x2e): undefined reference to
    collect2: error: ld returned 1 exit status
    Error: linker exited with status 1

I have confirmed I'm getting this error with dmd v2.092.0 but not with dmd
version v2.091.0. Thus a regression.

Known workarounds include:

- Omitting the `-debug` flag.
- Using the `-release` flag.
- Including the `-allinst` flag.
- Including the `-checkaction=C` flag.

I'm running Linux Mint 18 Sarah, but I've also been able to reproduce this in a
docker container based on Ubuntu Bionic Beaver

Jul 24 2020