public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lisp2d at lisp2d dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55038] New: c++11: operator += Date: Tue, 23 Oct 2012 17:02:00 -0000 [thread overview] Message-ID: <bug-55038-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55038 Bug #: 55038 Summary: c++11: operator += Classification: Unclassified Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: lisp2d@lisp2d.net I transfer code to c++(2011) version and hear: the main goal is to advance using an rvalue. But standard say that operators +=,++,-=,-- must have an lvalue from the left side. Who are writes the standard? And why I must to write cover class? And I want to hear an advice. code: #include <iostream> #include <complex> namespace test{ class Int{ public: signed int i; Int()noexcept:i(){} constexpr Int(Int const & x)noexcept:i{x.i}{} constexpr explicit Int(signed int const & x)noexcept:i{x}{} Int & operator =(Int const & x)noexcept{i = (x.i);return * this;} void Swap(Int & x){std::swap(i,x.i);} Int operator +(Int const & x){return Int{i + (x.i)};} Int & operator +=(Int const & x){i += (x.i);return * this;} }; int main(int,char * *){ Int x{1}; Int y{2}; Int z{3}; std::cout << "(" << x.i << "+" << y.i << ")+=" << z.i << " = " << ((x + y) += z).i << std::endl; std::complex<int> cx{1}; std::complex<int> cy{2}; std::complex<int> cz{3}; std::cout << "(" << cx << "+" << cy << ")+=" << cz << " = " << ((cx + cy) += cz) << std::endl; int ix{1}; int iy{2}; int iz{3}; //std::cout << "(" << ix << "+" << iy << ")+=" << iz << " = " << ((ix + iy) += iz) << std::endl; } } // namespace test int main(int n,char * * a){ return test::main(n,a);}
next reply other threads:[~2012-10-23 17:02 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-23 17:02 lisp2d at lisp2d dot net [this message] 2012-10-23 17:15 ` [Bug c++/55038] " redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-55038-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).