[Issue 4816] New: template constraint and __traits(compiles, ...) don't work properly together with a delegate

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 5 00:42:26 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4816

           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
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmail.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmail.com> 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)))
{
    func(args);
}

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


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
declaration
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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list