Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9069027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:19:25+00:00 2026-06-16T17:19:25+00:00

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

  • 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:19:27+00:00Added an answer on June 16, 2026 at 5:19 pm

    Following the comments made by @AlokSave, here is a later edit of the answer:

    Three are two possible explanations for this compiler flag. Since the documentation about it is scarce, it is somewhat unclear what its original meaning is, but there are, mainly, two possible explanations:

    1) Warning the user about returning an aggregate object make him aware that the stack could overflow if the aggregate object (which is allocated on the stack) is returned.

    2) Apparently, some old C compiler did not support returning aggrregates (you had to return a pointer).

    Which of the two is the best one, it is hard for me to judge. However, more relevant information about this flag may be found at the following links:

    http://bytes.com/topic/c/answers/644271-aggregate-return-warnings

    https://lists.gnu.org/archive/html/bug-gnulib/2012-09/msg00006.html

    Quoting from the latter link:

    In the GNU apps I’m familiar with (Emacs, coreutils, …)
    we simply disable -Waggregate-return. It a completely
    anachronistic warning, since its motivation was to
    support backwards compatibility with C compilers that
    did not allow returning structures. Those compilers
    are long dead and are no longer of practical concern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While looking through some old code I came across this gem: MyObject o =
While looking at some conceptual questions in C,I came across this question in a
While looking at the source code of the asyncore module I came across this
I've just saw an unfamiliar syntax while looking for GroupBy return type: public interface
While looking through the Spring MVC framework I noticed that, unless I misunderstand, its
While looking at some open source code to learn more about J2EE, I came
While looking through the log4j documentation I noticed that a database could be a
While looking at the Activity Monitor in SQL Server, I notice that under the
While looking at Microsoft's web site, I discovered that they no longer recommend using
While looking for keyboard-accessible menus, I stumbled across this question , which has as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.