www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23799] New: Link error with -betterC

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

          Issue ID: 23799
           Summary: Link error with -betterC
           Product: D
           Version: D2
          Hardware: x86_64
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: zan77137 nifty.com

In the dmd.2.103.0-rc.1, the following code causes a link error when built with
the -betterC compile option:
-----------------
struct Data
{
        Data[] range;
        string test;
}

Data[] foo()
{
        Data[] ret;
        if (__ctfe)
        {
                Data tmp;
                tmp.range ~= Data.init;
                ret ~= tmp;
        }
        return ret;
}

void func(Data dat)()
{
}

void bar(Data dat)()
{
        if (dat.test.length)
                func!(dat.range[0])();
}

extern (C) void main()
{
        static immutable data = foo();
        bar!(data[0])();
}
-----------------

$ dmd -betterC main.d
/usr/bin/ld: main.o: in function `main':
main.d:(.text.main[main]+0x5): undefined reference to
`_D4main__T3barVSQo4DataS2A1S2nnnZQxFNaNbNiNfZv'
collect2: error: ld returned 1 exit status

--
Mar 22 2023