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);
}
```
Comment #1 by davidbennett — 2019-06-23T03:54:40Z
Here is a reduced case, it seems like the algorithm dies at the static if making the inner template not match, in-turn preventing the pragma and static if from running.
For example if you remove the static if in this example the pragma will run.
```
template fun3()
{
template fun3(T)
{
pragma(msg, "test pragma");
static if(true)
void fun3(T t){}
}
}
void main()
{
fun3!()(1);
}
```
Comment #2 by davidbennett — 2019-06-25T00:37:02Z
I forgot to add the current error output for the above example:
onlineapp.d(13): Error: template onlineapp.fun3!().fun3 cannot deduce function from argument types !()(int), candidates are:
onlineapp.d(3): onlineapp.fun3!().fun3(T)
Comment #3 by robert.schadek — 2024-12-13T19:04:18Z