Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22306

Confusion in regards to purpose/behavior of -Waggregate-return?

$
0
0

While looking at the GCC's warning options, I came across -Waggregate-return.

-Waggregate-return
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.)


small example that elicits the warning:

class foo{};foo f(void){return foo{};}int main(){}

$ g++ -std=c++0x -Waggregate-return -o main main.cpp
main.cpp: In function ‘foo f()’:
main.cpp:2:5: warning: function returns an aggregate [-Waggregate-return]


another small example that does not elicit the warning:

#include <string>std::string f(void){return "test";}int main(){}

What is the benefit gained from using -Waggregate-return?
Why would someone want to be warned about this?
Also, isn't std::string a class?- why arn't I warned about the 'returned aggregate' in the second example?


Viewing all articles
Browse latest Browse all 22306

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>