title: Why does Visual Studio compiler allow violation of private inheritance in this example?
body: <p>I found very strange behavior of <code>std::unique_ptr</code> in Visual Studio 2013 and 2017. Let's consider an example:</p>
  
  <pre><code>class Base 
  {
  public:
      virtual ~Base() = default;
      virtual void Foo() = 0;
  };
  
  class Derived : private Base 
  {
  public:
      void Foo() override
      {
          std::cout &lt;&lt; "Foo";
      }
  };
  
  void Foo(std::unique_ptr&lt;Base&gt; a)
  {
      a-&gt;Foo();
  }
  
  Foo(std::unique_ptr&lt;Base&gt;(new Derived())); // Compiles
  </code></pre>
  
  <p>Note that inheritance is private. This example compiles only on Visual Studio. Moreover, the virtual function call works because it is public inheritance. So we have encapsulation violation since the cast from <code>Derived</code> to <code>Base</code> should be inaccessible. Can anybody explain why Visual Studio allows this? Is it a known issue? </p>
  
  <p>The line below doesn't compile for reasonable causes. The only difference between the first and second usages is in the second, the named object <code>B</code> is created.</p>
  
  <pre><code>std::unique_ptr&lt;Base&gt; B(new Derived()); // Doesn't compile
  </code></pre>
  
  <p>Is it related somehow with <a href="https://connect.microsoft.com/VisualStudio/feedback/details/540343/visual-c-compiler-downcasting-for-private-inheritance-with-static-cast-succeedes" rel="nofollow noreferrer">this issue</a> which still isn't fixed?</p>