[Issue 16347] New: Strange deprecation message when using templates
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Mon Aug  1 11:41:10 PDT 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=16347
          Issue ID: 16347
           Summary: Strange deprecation message when using templates
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dev at nomad.so
I'm not really sure what's going on here but here's a test snippet:
module test;
import std.traits;
public template DUnitMethodIterator(T, string generator, int index = 0)
{
    private string getResult()
    {
        string code = "";
        static if (index < __traits(allMembers, T).length)
        {
            // Comment out either the following static if to avoid the
deprecation message...
            static if (MemberFunctionsTuple!(T, __traits(allMembers,
T)[index]).length) { }
            // or the following template call to avoid the deprecation message.
            code ~= DUnitMethodIterator!(T, generator, index + 1);
        }
        return code;
    }
    enum DUnitMethodIterator = getResult();
}
private template MethodDelegateProperty(func...) { }
public mixin template Mockable(C)
{
    static public auto getMock(A...)(A args)
    {
        return new Mock!(C)(args);
    }
    private static class Mock(C)
    {
        mixin(DUnitMethodIterator!(C, "MethodDelegateProperty!(func)"));
    }
}
unittest
{
    static class T
    {
        mixin Mockable!T;
    }
    auto mock = T.getMock();
}
Building this code using the following command issues a deprecation message:
$ dmd -c -unittest test.d
/usr/include/dmd/phobos/std/traits.d(3677): Deprecation:
test.__unittestL40_1.T.Mockable!(T).Mock(C) if (is(C == class) || is(C ==
interface)) is not visible from module traits
Removing the commented lines of code (and rebuilding) removes the deprecation
message.
--
    
    
More information about the Digitalmars-d-bugs
mailing list