title: rvalue reference and move of a local variable
body: <p>In this snippet, I allocate a local object B that I pass to the constructor of another object C which takes it as a rvalue reference. I then put the latter into a container.</p>
  
  <p>When I retrieve C and static_cast its member back to B, the value is incorrect (and valgrind identifies 18 errors!)</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;vector&gt;
  
  class A {
  public:
    virtual ~A() {};
  };
  
  class B: public A {
  public:
    B(int foo) : _foo(foo) {}
    int _foo;
  };
  
  class C {
  public:
    C(A&amp;&amp; a): _a(std::move(a)) {}
    A&amp;&amp; _a;
  };
  
  std::vector&lt;C&gt; v;
  
  void bar() {
    v.emplace_back(B(12));
  }
  
  int main() {
    bar();
    C&amp;&amp; c = std::move(v.front());
    std::cout &lt;&lt; static_cast&lt;B&amp;&amp;&gt;(c._a)._foo &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  
  <p>My understanding is that, as C takes a rvalue reference, there should not be any object slicing. I should still be able to retrieve a full B object. Additionally, my understanding (most probably flawed) of <code>std::move</code> is that I can 'move' a local variable out of its context and that by taking a rvalue reference, C takes ownership of B.</p>
  
  <p>The output is <code>39931504</code> instead of <code>12</code>.</p>
  
  <p>Anyone could explain to me what is going on?</p>