title: Is it dangerous to return MPI_Request and MPI_Status objects by value?
body: <p>I'm writing a light wrapper in C++ for MPI. To make things easier, I have some functions return an <code>MPI_Request</code> object rather than take one as a pointer. The code works fine on my computer, although I'm concerned it could cause problems with a different implementation of MPI. </p>
  
  <p>Below is some example code: </p>
  
  <pre><code>template&lt;class T&gt; MPI_Request ireceive(T* data, int count, int source, int tag)
  {
      MPI_Request request;
      MPI_Irecv(data, get_mpi_type&lt;T&gt;::mul * count, get_mpi_type&lt;T&gt;::type(), source, tag, MPI_COMM_WORLD, &amp;request);
      return request;
  }
  template&lt;class T&gt; MPI_Request ireceive(std::vector&lt;T&gt;&amp; dest, int source, int tag)
  {
      MPI_Status status = probe(source, tag);
      int size = get_msg_size&lt;T&gt;(status);
      dest.clear();
      dest.resize(size);
      return ireceive(&amp;dest[0], size, source, tag, status);
  }
  MPI_Status wait(MPI_Request&amp; request)
  {
      MPI_Status status;
      MPI_Wait(&amp;request, &amp;status);
      return status;
  }
  MPI_Status test(MPI_Request&amp; request, int&amp; flag)
  {
      MPI_Status status;
      MPI_Test(&amp;request, &amp;flag, &amp;status);
      return status;
  }
  </code></pre>
  
  <p>The first two functions directly return a MPI_Request object, and the second two functions return an MPI_Status object. I am concerned that, with another MPI implementation, these functions could cause undefined behavior. </p>
  
  <p><strong>Is it dangerous to return MPI_Request and MPI_Status objects by value?</strong></p>