D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21753 - Struct literal with function literal member not allowed as template value argument
Summary: Struct literal with function literal member not allowed as template value arg...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-03-24 02:43 UTC by Boris Carvajal
Modified: 2021-04-03 11:13 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Boris Carvajal 2021-03-24 02:43:25 UTC
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.
Comment 1 Dlang Bot 2021-03-24 02:52:02 UTC
@BorisCarvajal created dlang/dmd pull request #12300 "Fix Issue 21753 - Struct literal with function literal member not allowed" fixing this issue:

- Fix Issue 21753 - Struct literal with function literal member not allowed as template value argument

https://github.com/dlang/dmd/pull/12300
Comment 2 Dlang Bot 2021-03-24 04:40:06 UTC
dlang/dmd pull request #12300 "Fix Issue 21753 - Struct literal with function literal member not allowed" was merged into master:

- abe4ac1b6a3b89865076cc6f33ff18f29d24bd58 by Boris Carvajal:
  Fix Issue 21753 - Struct literal with function literal member not allowed as template value argument

https://github.com/dlang/dmd/pull/12300
Comment 3 Dlang Bot 2021-04-03 11:13:08 UTC
dlang/dlang.org pull request #2989 "abi: add mangling for issue 21753" was merged into master:

- e268c4b79dd79aa1198f48372bad86f695c0f40c by Boris Carvajal:
  abi: add mangling for issue 21753

https://github.com/dlang/dlang.org/pull/2989