[Issue 19999] New: compile time logic (pragma, static if) in sub eponymous templates are ignored
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 23 02:39:34 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19999
Issue ID: 19999
Summary: compile time logic (pragma, static if) in sub
eponymous templates are ignored
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: davidbennett at bravevision.com
In the below example fun1 compiles fine and outputs 2 "run template constraint"
messages.
However fun2 does not compile and does not output any pragma messages.
```
struct Type(Args...)
{
alias args = Args;
}
// This works
template fun1(Args...)
{
pragma(msg, "run template constraint");
template fun1(T) if(__traits(compiles, { enum _ = T.args; }))
{
alias S = Type!(T.args,Args);
auto fun1(T t){
S s;
return s;
}
}
}
// This does not
template fun2(Args...)
{
template fun2(T)
{
pragma(msg, "run static if");
static if(__traits(compiles, { enum _ = T.args; }))
{
alias S = Type!(T.args,Args);
auto fun2(T t){
S s;
return s;
}
}
}
}
void main()
{
Type!() t;
auto s1 = t.fun1!(1, 2).fun1!(3, 4);
assert(s1.args.length == 4);
auto s2 = t.fun2!(1, 2).fun2!(3, 4);
assert(s2.args.length == 4);
}
```
--
More information about the Digitalmars-d-bugs
mailing list