February 07, 2020
https://issues.dlang.org/show_bug.cgi?id=20565

          Issue ID: 20565
           Summary: Local template function in static foreach yields link
                    error LNK1179 on fresh compile
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: simon.vanbernem@yahoo.de

Minimized Repro:

//--------------------------------------
struct A_Attributes{
        int attr;
}

struct A{
        @A_Attributes(2)
        int a;
        @A_Attributes(2)
        int b;
}

import std.traits, core.stdc.stdio;

void main(){
        static foreach(string field_name; FieldNameTuple!A){{
                alias member = __traits(getMember, A, field_name);
                void temp(Attribute_Type)(){ printf("hello"); }
                static if(hasUDA!(member, A_Attributes)){{ temp!A_Attributes();
}}
        }}
}
//--------------------------------------


Compiling this with DMD32 D Compiler v2.087.0 will yield the following error:

test.obj : fatal error LNK1179: Ungültige oder beschädigte Datei: COMDAT "_D4test4mainFZ__T4tempTSQw12A_AttributesZQyMFNbNiZv" doppelt vorhanden. Error: linker exited with status 1179

(The german means: "invalid or corrupt file: COMDAT -mangled- exists twice")

It gets even weirder: If you comment out one of the lines that say "@A_Attributes(2)" it compiles. If you then uncomment that line again, the code still compiles. No link error. The link error reappears as soon as I delete the files that were built.

--