Make shadowing mixin template names an error (5 years old problem)

mw mw at gmail.com
Tue May 5 21:47:09 UTC 2026


Make shadowing mixin template names an error

https://github.com/dlang/dmd/issues/23060#issuecomment-4374242813

```
$ cat ctor_bug.d

template Singleton(T) {

     private this() {}  // private, so nobody can new T()!

     // Cache instantiation flag in thread-local bool
     // Thread local
     private static bool instantiated_;

     // Thread global
     private __gshared T instance_;

     static T getSingleton()
     {
         if (!instantiated_)
         {
             synchronized(T.classinfo)
             {
                 if (!instance_)
                 {
                     instance_ = new T();
                 }

                 instantiated_ = true;
             }
         }

         return instance_;
     }
}

class A {
   mixin Singleton!A;

   this() {}  // no dup this() error here!

}

$ dmd -c ctor_bug.d  # no error reported


$ dmd --version
DMD64 D Compiler v2.112.0
```

This bug breaks the Singleton pattern



More information about the Digitalmars-d mailing list