kubo39's blog

ただの雑記です。

getFunctionAttributesでlive関数属性をとれるようにした

これ https://github.com/dlang/dmd/pull/11049

単にtraits.dを修正するだけではだめだった、というのはlive関数属性は名前修飾の定義も実装もされていなかったので、typeof内で普通の関数と区別されていなかったのである。

具体的に言うと以下のようになってしまう。

alias tuple(T...) = T;

struct S1
{
    int f1() @live { return 42; }
    int f2() { return 42; }
}

static assert(__traits(getFunctionAttributes, typeof(S1.f1)) == tuple!("@live", "@system"));
static assert(__traits(getFunctionAttributes, typeof(S1.f2)) == tuple!("@live", "@system"));

struct S2
{
    long f2() { return 0; }
    long f1() @live { return 42; }
}

static assert(__traits(getFunctionAttributes, typeof(S2.f1)) == tuple!("@system"));
static assert(__traits(getFunctionAttributes, typeof(S2.f2)) == tuple!("@system"));

という小ネタがおもしろかったというだけの話。