www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13830] New: Circular dependency between interface and


          Issue ID: 13830
           Summary: Circular dependency between interface and
                    implementation segfault the compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

I tried to use the CRTP in D to generate an interface at compile time based on
another interface and the implementation. Unfortunately, it segfaulted the

import std.stdio, std.traits;

template RESTServer(I, Impl) {
        private abstract class IRESTServer/* : I*/ {
                //final override void test() { assert(0); }                     
                void test(Context ctx);
        int abuseTheCompiler() {
                foreach (method; __traits(allMembers, Impl)) {
                        foreach (overload; MemberFunctionsTuple!(Impl, method))
                                pragma(msg, __traits(identifier, overload));
                return 42;
        static assert(abuseTheCompiler());
        alias RESTServer = IRESTServer;

struct Context { string ip; }

interface MyAPI { void test(); }

class MyAPIImpl : RESTServer!(MyAPI, MyAPIImpl) {
        void test(Context ctx) {

void main() {
        auto c = new MyAPIImpl();

Question: should such code be valid ? It allows an interesting pattern for code

Dec 07 2014