www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23148] New: Missing invariant symbol with static library when


          Issue ID: 23148
           Summary: Missing invariant symbol with static library when
                    template function declares struct with destructor and
                    invariant that instantiates template with lambda, also
                    main has a lambda
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de

What an odyssey!


struct Struct {
    SumType!() v1;
void foo()() { SumType!() v2; }
struct SumType() {
    ~this() { }
    invariant { alias a = {}; match!a(); }

void match(alias handler)() { }


import a;
alias l = _ => 0;
void main() {

dmd a.d -of=liba.a -lib
dmd b.d -L-L. -L-la

undefined reference to

This regression was introduced with

The relevant snippet is the assignment of instantiating module in
dtemplate.d:6296. If the check for tinst/tinst.minst is removed, so that the
block for tnext runs, as it did before the commit, the error disappears.

The linker error seems to come down to a disagreement between dmd a.d and dmd
b.d on what the name of the generated invariant in SumType should be. In the
failing case, there is an undefined reference to invariant4 in b.o, but a
definition of invariant3 in a.o.

This bug report seems similar to https://issues.dlang.org/show_bug.cgi?id=21723
, but it's different enough in detail that I decided to file a separate pr

On suggestion of opDispatch in #d, I tried changing __invariant name generation
to use line number rather than idCounter for suffix. With that, the linker
error disappeared.

May 30 2022