Bug 16347 – Strange deprecation message when using templates

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-08-01T18:41:10Z
Last change time
2017-11-23T11:43:29Z
Assigned to
No Owner
Creator
Gary Willoughby

Comments

Comment #0 by dev — 2016-08-01T18:41:10Z
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.
Comment #1 by dev — 2016-08-01T18:42:14Z
I simplified the code snippet above, the deprecation is now as follows: /usr/include/dmd/phobos/std/traits.d(3677): Deprecation: test.__unittestL38_1.T.Mockable!(T).Mock(C) is not visible from module traits
Comment #2 by ag0aep6g — 2016-08-01T19:19:20Z
Reduced further: ---- module test; import std.traits; alias m = MemberFunctionsTuple!(T, "Mock"); class T { auto getMock() { return new Mock; } private static class Mock {} } ----
Comment #3 by razvan.nitu1305 — 2017-11-23T11:43:29Z
Running the example on git HEAD on Ubuntu 16.04 results in successful compilation (no warnings). Closing this as WORKSFORME.