April 05, 2021
https://issues.dlang.org/show_bug.cgi?id=21800

          Issue ID: 21800
           Summary: Unused delegate template parameter scope incorrectly
                    inferred
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: eyal@weka.io

This program fails to compile in the "ignore!..." line.

  @nogc nothrow void ignore(alias F)() {}
  @nogc nothrow void call(alias F)() { F(); }

  @nogc
  void main() {
      int x;

      ignore!(()=>x)();           // delegate causes "x" to come from GC

      call!(()=>x)();             // is fine
  }

It compiles fine if the "ignore!" line is commented out.

If a delegate is unused, surely its scope is at least as narrow as a delegate that is used.

Why is @nogc inference not done on the template instantiation result?

--