[Issue 21753] New: Struct literal with function literal member not allowed as template value argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 24 02:43:25 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21753

          Issue ID: 21753
           Summary: Struct literal with function literal member not
                    allowed as template value argument
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: boris2.9 at gmail.com

From: https://forum.dlang.org/post/syxnzddlnkfwtbvrdfsr@forum.dlang.org

```d
import std.stdio;

struct Sample{
  void function() func1;
  void function() func2;
}

void noth(Sample smpl)() {
  smpl.func1(); // Error: expression __lambda1 is not a valid template value
argument
  smpl.func2(); // Error: expression __lambda2 is not a valid template value
argument
}

void main(){
  enum s = Sample(
    {writeln("Hello world1");},
    {writeln("Hello world2");}
  );
  s.func1();
  s.func2();
  noth!(s)();
}
```

A function literal can be a template value argument and the spec says that
"struct literals of template value arguments" are too, so this should be
allowed.

--


More information about the Digitalmars-d-bugs mailing list