In another thread [0] this function can be used to call non nogc code from nogc code

import std.traits;

auto assumeNoGC(T)(T t) {
    enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) t;
}

And then you can use it like:

@nogc unittest {
  auto allocate() {
    return [1];
  }
  assumeNoGC({allocate;})();
}

So I tried to the same with pure, wrote assumePure and changed the attribute to FunctionAttribute.pure_, but that doesn't seem to be treated the same:

pure unittest {
  static int thing = 3;
  void modify() {
    thing = 4;
  }
  assumePure({modify;})();
}

Ye get: pure function modify cannot access mutable static data thing

Why does it work with nogc but not with pure?

Cheers,
- Ali

[0]: https://forum.dlang.org/thread/awalwokejtywzkxgd...@forum.dlang.org

Reply via email to