title: Can't pass temporary object as reference
body: <p>This is a very minimal example:</p>
  <pre><code>class Foo
  {
  public:
      Foo(int x) {};
  };
  
  void ProcessFoo(Foo&amp; foo)
  {
  }
  
  int main()
  {
      ProcessFoo(Foo(42));
      return 0;
  }
  </code></pre>
  <p>The above compiles fine on Visual Studio, but generates an error on Linux and Mac.</p>
  <p>Compiling the above generates this:</p>
  <pre><code>$ g++ -std=c++11 -c newfile.cpp
  
  newfile.cpp: In function ‘int main()’:
  newfile.cpp:23:23: error: invalid initialization of non-const reference of type ‘Foo&amp;’ from an rvalue of type ‘Foo’
       ProcessFoo(Foo(42));
                         ^
  newfile.cpp:14:6: note: in passing argument 1 of ‘void ProcessFoo(Foo&amp;)’
   void ProcessFoo(Foo&amp; foo)
  </code></pre>
  <p>I've found three workarounds:</p>
  <ol>
  <li>Create a temp variable for the invocation of ProcessFoo.</li>
  </ol>
  <p>Like this:</p>
  <pre><code>Foo foo42(42);
  ProcessFoo(foo42);
  </code></pre>
  <ol start="2">
  <li><p>ProcessFoo takes a const reference: <code>void ProcessFoo(const Foo&amp; foo)</code></p>
  </li>
  <li><p>ProcessFoo just lets Foo get passed by value. <code>void ProcessFoo(Foo foo)</code></p>
  </li>
  </ol>
  <p>Why is the compiler forbidding my original code? (What is it guarding against)?  What is it about each of the three workarounds above that satisfies the compiler?  What would MSVC allow it, but not g++?</p>