Skip to content

Commit 507fe24

Browse files
Bolpat0xEAB
authored andcommitted
Respect linkage
1 parent 6876632 commit 507fe24

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

std/functional.d

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,16 @@ if (isCallable!(F))
18151815
}
18161816
else static if (is(F Func == Func*) && is(Func == function) && is(Func Params == __parameters))
18171817
{
1818-
alias dg = delegate(Params params) const => F.init(params);
1819-
typeof(dg) result; // inlining `dg` infers attributes incorrectly
1818+
// https://issues.dlang.org/show_bug.cgi?id=24007 - cannot specify linkage on function literal:
1819+
//alias dg = delegate(Params params) const => F.init(params);
1820+
//typeof(dg) result;
1821+
// Workaround:
1822+
struct S
1823+
{
1824+
mixin("extern(", __traits(getLinkage, fp), ") auto ref dg(Params params) const => F.init(params);");
1825+
}
1826+
typeof(&S().dg) result; // inlining `dg` infers attributes incorrectly
1827+
18201828
() @trusted
18211829
{
18221830
// assigning funcptr is @system, but it’s safe here because `fp` needs no context
@@ -1831,7 +1839,7 @@ if (isCallable!(F))
18311839
}
18321840
else
18331841
{
1834-
alias DelType = typeof(&(new DelegateFaker!(F)).doIt);
1842+
alias DelType = typeof(&(new DelegateFaker!F).doIt);
18351843

18361844
static struct DelegateFields {
18371845
union {
@@ -1852,7 +1860,7 @@ if (isCallable!(F))
18521860

18531861
df.contextPtr = cast(void*) fp;
18541862

1855-
DelegateFaker!(F) dummy;
1863+
DelegateFaker!F dummy;
18561864
auto dummyDel = &dummy.doIt;
18571865
df.funcPtr = dummyDel.funcptr;
18581866

0 commit comments

Comments
 (0)