[Issue 19945] New: In betterC strange linker error can occur when importing alias of template struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 7 04:50:48 UTC 2019


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

          Issue ID: 19945
           Summary: In betterC strange linker error can occur when
                    importing alias of template struct
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: n8sh.secondary at hotmail.com

I reproduced this problem with DMD v2.086.0 and DMD v2.085.1 and LDC 1.15.0. I
did not test other versions of DMD or LDC.

### 1. This works with -betterC.
---
extern(C) void main()
{
    import std.random : LinearCongruentialEngine;
    enum A = 48_271, B = 0, C = 2_147_483_647;
    alias MyMinstdRand = LinearCongruentialEngine!(uint, A, B, C);
    MyMinstdRand gen;
    auto n = gen.front;
}
---

### 2. This works with -betterC.
---
extern(C) void main()
{
    import std.random : LinearCongruentialEngine, MinstdRand;
    enum A = 48_271, B = 0, C = 2_147_483_647;
    alias MyMinstdRand = LinearCongruentialEngine!(uint, A, B, C);
    static assert(is(MyMinstdRand == MinstdRand), "definitions are identical");
}
---

### 3. But there is a linker error if they are combined when using -betterC.
---
extern(C) void main()
{
    import std.random : LinearCongruentialEngine, MinstdRand;
    enum A = 48_271, B = 0, C = 2_147_483_647;
    alias MyMinstdRand = LinearCongruentialEngine!(uint, A, B, C);
    static assert(is(MyMinstdRand == MinstdRand), "definitions are identical");
    MyMinstdRand gen; // error: undefined reference to
'_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc6__initZ'
    auto n = gen.front; //error: undefined reference to
'_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc5frontMxFNaNbNdNiNfZk'
}
---

### 4. The same error occurs with -betterC when trying to use MindstdRand
directly.
---
extern(C) void main()
{
    import std.random : MinstdRand;
    MinstdRand gen; // error: undefined reference to
'_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc6__initZ'
    auto n = gen.front; // error: undefined reference to
'_D3std6random__T24LinearCongruentialEngineTkVki48271Vki0Vki2147483647ZQCc5frontMxFNaNbNdNiNfZk'
}
---

--


More information about the Digitalmars-d-bugs mailing list