title: When and why would I use -fno-elide-constructors?
body: <p>I'm learning C++ and I came across the <code>-fno-elide-constructors</code>, below I have included the description from the man page.</p>
  
  <pre><code>   -fno-elide-constructors
         The C++ standard allows an implementation to omit creating a
         temporary which is only used to initialize another object of the
         same type.  Specifying this option disables that optimization, and
         forces G++ to call the copy constructor in all cases.
  </code></pre>
  
  <p>So with this option I am able disable this particular type of compiler optimization. I have a program that creates 2 objects and adds them together and prints when each of the function is called using using BASIC4TRACE library. I compiled the same program to test the difference in function calls while using this option twice, one with and one without, giving this output.</p>
  
  <pre><code>Without optimizations
  
  BASIC4TRACE: (0x7fff7504a7c0)-&gt;Object(const char *)
  BASIC4TRACE: (0x7fff7504a7d0)-&gt;Object(const char *)
  BASIC4TRACE: (0x7fff7504a770)-&gt;Object(const char *)
  BASIC4TRACE: op+(const Object&amp;, const Object&amp;)
  BASIC4TRACE: (0x7fff7504a720)-&gt;Object()
  BASIC4TRACE: (0x7fff7504a780)-&gt;Object(const Object&amp;)
  BASIC4TRACE: (0x7fff7504a720)-&gt;~Object()
  BASIC4TRACE: op+(const Object&amp;, const Object&amp;)
  BASIC4TRACE: (0x7fff7504a720)-&gt;Object()
  BASIC4TRACE: (0x7fff7504a790)-&gt;Object(const Object&amp;)
  BASIC4TRACE: (0x7fff7504a720)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a7f0)-&gt;Object(const Object&amp;)
  BASIC4TRACE: (0x7fff7504a790)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a780)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a770)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a7e0)-&gt;Object(const Object&amp;)
  BASIC4TRACE: (0x7fff7504a7f0)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a7e0)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a7d0)-&gt;~Object()
  BASIC4TRACE: (0x7fff7504a7c0)-&gt;~Object()
  
  With optimizations
  
  BASIC4TRACE: (0x7fffbfc8bbf0)-&gt;Object(const char *)
  BASIC4TRACE: (0x7fffbfc8bc00)-&gt;Object(const char *)
  BASIC4TRACE: (0x7fffbfc8bbb0)-&gt;Object(const char *)
  BASIC4TRACE: op+(const Object&amp;, const Object&amp;)
  BASIC4TRACE: (0x7fffbfc8bbc0)-&gt;Object()
  BASIC4TRACE: op+(const Object&amp;, const Object&amp;)
  BASIC4TRACE: (0x7fffbfc8bc10)-&gt;Object()
  BASIC4TRACE: (0x7fffbfc8bbc0)-&gt;~Object()
  BASIC4TRACE: (0x7fffbfc8bbb0)-&gt;~Object()
  BASIC4TRACE: (0x7fffbfc8bc10)-&gt;~Object()
  BASIC4TRACE: (0x7fffbfc8bc00)-&gt;~Object()
  BASIC4TRACE: (0x7fffbfc8bbf0)-&gt;~Object()
  </code></pre>
  
  <p>As you can see there is a significant difference in the number of calls made. So my question is when would I actually use this option? Is there a specific case where this type of optimization causes problems? I can't really think of a situation where I wouldn't want my code to be optimized as much as possible so I am having a hard time trying to figure out what this is good for. </p>