title: Confusion in regards to purpose/behavior of -Waggregate-return?
body: <p>While looking at the <a href="http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#Warning-Options" rel="noreferrer">GCC's warning options</a>,  I came across <em>-Waggregate-return</em>.</p>
  
  <blockquote>
    <p><strong>-Waggregate-return</strong><br>
    Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.) </p>
  </blockquote>
  
  <hr>
  
  <p><strong>small example that elicits the warning:</strong></p>
  
  <pre><code>class foo{};
  foo f(void){return foo{};}
  int main(){}
  </code></pre>
  
  <blockquote>
    <p>$ g++ -std=c++0x -Waggregate-return -o main main.cpp<br>
    main.cpp: In function ‘foo f()’:<br>
    main.cpp:2:5: warning: function returns an aggregate [-Waggregate-return]</p>
  </blockquote>
  
  <hr>
  
  <p><strong>another small example that does not elicit the warning:</strong></p>
  
  <pre><code>#include &lt;string&gt;
  std::string f(void){return "test";}
  int main(){}
  </code></pre>
  
  <hr>
  
  <p>What is the benefit gained from using -Waggregate-return?<br>
  Why would someone want to be warned about this?<br>
  Also, isn't std::string a class?- why arn't I warned about the 'returned aggregate' in the second example?</p>