title: Compiler reports 'deleted' operator = , but it is there
body: <p>I ran into a nasty issue, where the compiler claims an <code>operator=</code> is deleted, but it is there. After several hours of trying around, I produced a minimal solution that reproduces the issue. I am using MSVC Community Edition 2017 15.7.5 (the newest as of today, 2018-07-20), and have set it to 'C++17'</p>
  
  <p>The code is not trivial; the concept is that a template class TT is used to enforces the existence of a static member function <code>foo</code> in a group of classes <code>Fn</code>. This is very similar to a <em>factory pattern</em>, just this solution doesn't create class instances, but reports static detail info about the class.</p>
  
  <p>The error is reported on the assignment in the last line, and reads (full error list at the bottom):</p>
  
  <blockquote>
    <p>"error C2280: 'C &amp;C::operator =(const C &amp;)': attempting to reference a
    deleted function"</p>
  </blockquote>
  
  <p>But line 5 defined this operator, right with those decorators?</p>
  
  <p>The assignment that fails tries to assign a returned <code>const std::vector&lt;C&gt;&amp;</code> to a class member variable.<br>
  I thought the <code>const</code> is producing the issue, but removing all of the <code>const</code> in each function does not make any difference; same error in the same line.</p>
  
  <p><strong>Question: Why does the compiler report this, and what is a possible fix?</strong><br>
  I think this must be something silly I miss, but I can't find it.</p>
  
  <pre><code>#include &lt;vector&gt;
  
  class C
  {
  public:
    C(int ii) : i(ii) {}
    C&amp; operator=(const C&amp;) = default;    /// HERE is the assignment operator
    const int i;
  };
  typedef std::vector&lt;C&gt; CVec;   // shorthand for a vector of C's
  
  template &lt;class T&gt;   // this template forces classes F1, F2, ... to have a static member function 'foo'
  class TT {
  public:
    static const CVec&amp; foo(void) { return T::foo(); }
  };
  
  class F1  // one of many Fn classes
  {
  public:
    static const CVec&amp; foo(void) { static CVec cv{ C{ 1 }, C{ 2 } }; return cv; }    // static member as forced by template
    //...
  };
  class F2  // another one of many Fn classes
  {
  public:
    static const CVec&amp; foo(void) { static CVec cv{ C{ 3 } }; return cv; }     // static member as forced by template
    //...
  };
  
  class D    // controller class
  {
  public:
    CVec cv;
    const CVec&amp; bar(int z)   // function to select one of the subclasses
    {
      switch (z)
      {
        case 1: return TT&lt;F1&gt;::foo();
        case 2: return TT&lt;F2&gt;::foo();
          //...
      }
    }
  
    void foobar(void)  //selector (from user input)
    {
      int z = 2; // user input
      cv = bar(z);   // THIS assignment produces the error
    }
  };
  </code></pre>
  
  <p>Full Error Text:</p>
  
  <pre><code>------ Build started: Project: BG, Configuration: Debug Win32 ------
  bgcore.cpp
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xutility(2443): error C2280: 'C &amp;C::operator =(const C &amp;)': attempting to reference a deleted function
  d:\projects\bg\core\bgcore.h(8): note: see declaration of 'C::operator ='
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\xutility(2462): note: see reference to function template instantiation '_OutIt std::_Copy_unchecked1&lt;_InIt,_OutIt&gt;(_InIt,_InIt,_OutIt,std::_General_ptr_iterator_tag)' being compiled
          with
          [
              _OutIt=C *,
              _InIt=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1430): note: see reference to function template instantiation '_OutIt *std::_Copy_unchecked&lt;_Iter,C*&gt;(_InIt,_InIt,_OutIt)' being compiled
          with
          [
              _OutIt=C *,
              _Iter=C *,
              _InIt=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1448): note: see reference to function template instantiation 'void std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt;::_Assign_range&lt;_Iter&gt;(_Iter,_Iter,std::forward_iterator_tag)' being compiled
          with
          [
              _Ty=C,
              _Iter=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1448): note: see reference to function template instantiation 'void std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt;::_Assign_range&lt;_Iter&gt;(_Iter,_Iter,std::forward_iterator_tag)' being compiled
          with
          [
              _Ty=C,
              _Iter=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1471): note: see reference to function template instantiation 'void std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt;::assign&lt;C*,void&gt;(_Iter,_Iter)' being compiled
          with
          [
              _Ty=C,
              _Iter=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1471): note: see reference to function template instantiation 'void std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt;::assign&lt;C*,void&gt;(_Iter,_Iter)' being compiled
          with
          [
              _Ty=C,
              _Iter=C *
          ]
  c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.14.26428\include\vector(1457): note: while compiling class template member function 'std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt; &amp;std::vector&lt;_Ty,std::allocator&lt;_Ty&gt;&gt;::operator =(const std::vector&lt;_Ty,std::allocator&lt;_Ty&gt;&gt; &amp;)'
          with
          [
              _Ty=C
          ]
  d:\projects\bg\core\bgcore.h(49): note: see reference to function template instantiation 'std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt; &amp;std::vector&lt;_Ty,std::allocator&lt;_Ty&gt;&gt;::operator =(const std::vector&lt;_Ty,std::allocator&lt;_Ty&gt;&gt; &amp;)' being compiled
          with
          [
              _Ty=C
          ]
  d:\projects\bg\core\bgcore.h(22): note: see reference to class template instantiation 'std::vector&lt;C,std::allocator&lt;_Ty&gt;&gt;' being compiled
          with
          [
              _Ty=C
          ]
  Done building project "BG.vcxproj" -- FAILED.
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>