Code to reproduce
file: test1.d
extern(C) __gshared bool test = true;
void main() {}
file: test2.d
module test2;
import ldc.attributes : weak;
extern(C) __gshared @weak bool test = false;
pragma(msg, __traits(getAttributes, test)); // this triggers the error
command:
ldc2 -c test2.d && ldc2 test1.d test2.o
result
AliasSeq!(_weak())
/usr/bin/ld: test2.o:(.bss.test+0x0): multiple definition of `test'; test1.o:(.data.test+0x0): first defined here
collect2: error: ld returned 1 exit status
Observation
ldc defines most udas in arguments.d like this:
immutable weak = _weak();
private struct _weak {}
|
immutable weak = _weak(); |
uda.cpp scans symbols for attributes by checking isStructLiteralExp()
|
if (auto sle = attr->isStructLiteralExp()) |
but if expressionSemantic was run prior to this check, the attr expression is VarExp and the check fails.
A simple __traits(getAttributes, sym) can trigger this error.
Changing immutable to enum fixes the issue, but there is probably a reason immutable was chosen.
Code to reproduce
file: test1.d
file: test2.d
command:
ldc2 -c test2.d && ldc2 test1.d test2.oresult
Observation
ldc defines most udas in arguments.d like this:
ldc/runtime/druntime/src/ldc/attributes.d
Line 424 in 3883e04
uda.cpp scans symbols for attributes by checking
isStructLiteralExp()ldc/gen/uda.cpp
Line 98 in 3883e04
but if
expressionSemanticwas run prior to this check, theattrexpression isVarExpand the check fails.A simple
__traits(getAttributes, sym)can trigger this error.Changing
immutabletoenumfixes the issue, but there is probably a reasonimmutablewas chosen.