This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/80243] c++ doesn't allow function to return a struct (or object?) - same thing
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 29 Mar 2017 08:33:22 +0000
- Subject: [Bug c++/80243] c++ doesn't allow function to return a struct (or object?) - same thing
- Auto-submitted: auto-generated
- References: <bug-80243-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80243
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your second example doesn't compile for a very simple reason:
(In reply to Jim Michaels from comment #1)
> #include <string>
> #include <initializer_list>
> typedef struct {std::string s;int i;} Structsb;
> Structsb fn(std::string s1, int i1) {
> return {s1,i1};
> }
> int main() {}
I'm guessing you didn't mean to put a closing brace here?
> Structsb structsb=fn("string",1);
> return strustsb.i;
> }
Do you see what I mean about reporting bugs every time your code doesn't
compile? This is a simple mistake, not a bug in GCC. Stop assuming everything
is a bug in GCC, which has hundreds of thousands of hours of development and
testing by very talented people who understand C++ very well. If something
trivial like returning a struct didn't work somebody would have noticed before
you did. You're not the only user of GCC.