import std.traits : isCallable; struct MyStruct { auto foo() { return MyStruct(); } static if (isCallable!foo) pragma(msg, "GOOD"); else pragma(msg, "BAD"); } Prints "GOOD" if foo returns 'MyStruct' instead of 'auto'. Member function foo is actually usable in both cases. I'm unsure whether this is a Phobos problem or a compiler problem. Using DMD32 v2.074.0 or LDC2 v1.1.1 (which is based on DMD v2.071.2).
This has to do with the order of symbol resolving. You will see that it will print good, if you put the static if outside of the struct body.
(In reply to uplink.coder from comment #1) > This has to do with the order of symbol resolving. > You will see that it will print good, if you put the static if outside of > the struct body. Thanks for the prompt answer. Do you mean that this is the intended behavior, or is it still a bug? I'll explain what I'm trying to achieve: a mixin template that will automatically define a member function foo if it is not already present. However, the fact that it works in some situations and not in others is mildly annoying. Maybe you can suggest a better approach?
I would classify this as a bug, however it seems like a fix for this would break other situations. for now the best workaround is to not use functions returning auto inside that struct.
I cannot reproduce this. The code in the bug report prints "GOOD" in both situations (return type "auto" or return type "MyStrut"). Closing as WORKSFORME.