Summary: template constraint and __traits(compiles, ...) don't
                    work properly together with a delegate
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Jonathan M Davis <> 2010-09-05 
00:42:07 PDT ---
The following refuses to compile

import std.stdio;

void callFunc(alias func, T...)(T args)
    if(__traits(compiles, func(args)))

void main()
    auto func = (){writeln(4);};

Rather, it gives you the error message

d.d(12): Error: template d.callFunc(alias func,T...) if
(__traits(compiles,func(args))) does not match any function template
d.d(12): Error: template d.callFunc(alias func,T...) if
(__traits(compiles,func(args))) cannot deduce template function from argument
types !(func)()
d.d(12): Error: template instance errors instantiating template

If I remove the template constraint, then it compiles fine. If I declare func
as a nested function and pass that, it works fine. If I use __traits(compiles,
func()) in main(), it returns true. However, the template constraint fails as
long as you pass it a delegate.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to