Bug 21138 – Difficult to treat UDAs given to parameters.

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-08T20:03:00Z
Last change time
2020-08-10T07:34:18Z
Assigned to
No Owner
Creator
SHOO

Comments

Comment #0 by zan77137 — 2020-08-08T20:03:00Z
Function arguments can be given UDAs, but they are very difficult to treat. ---------------------------------------------------------- import std; template Temp1(alias params) { alias Temp1 = params; } template Temp2(params...) { alias Temp2 = params; } template Foo(alias f) { // OK1 alias params = Parameters!(f); pragma(msg, params); // (@(10) int, @(15) long) // OK2 pragma(msg, params[0..1]); // (@(10) int) pragma(msg, __traits(getAttributes, params[0..1])); // tuple(10) // NG1: Lack UDAs alias param2 = params[0]; pragma(msg, params[0]); // int //pragma(msg, __traits(getAttributes, params[0])); // Error // NG2: Error //pragma(msg, Temp1!(params)); // NG3: This is able to pass, but lack UDAs pragma(msg, Temp2!(params)); } void main() { alias X = Foo!( (@(10) int x, @(15) long b) => x ); } ---------------------------------------------------------- In NG1 and NG3, UDAs should not lack. NG2 should allow them to be passed to an alias parameter, as is possible in OK1. But maybe this should be considered separately from this issue. (Allow tuple to be passed to an alias template parameter)
Comment #1 by simen.kjaras — 2020-08-10T07:34:18Z
Changing the behavior of template alias parameters to allow them to bind to tuples is a large breaking change, and is simply not going to happen, though I see the benefit in making it work the same there as alias works elsewhere. NG1 and NG3 are the samme issue, and is described in issue 19787 *** This issue has been marked as a duplicate of issue 19787 ***