public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "eyakubovich at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/44186] New: Wrong code generated with -O2 and above Date: Tue, 18 May 2010 03:37:00 -0000 [thread overview] Message-ID: <bug-44186-19197@http.gcc.gnu.org/bugzilla/> (raw) This is a stripped down code from proposed Boost.Move library. Asserts don't fire with -O0 and -O1 but do with -O2 and -O3 #include <assert.h> template <class T> class rv : public T { rv(); ~rv(); rv(rv const&); void operator=(rv const&); }; template <class T> rv<T>& move(T& x) { return *static_cast<rv<T>* >(&x); } //A movable class class movable { movable(movable &); movable& operator=(movable&); public: operator rv<movable>&() { return *reinterpret_cast< rv<movable>* >(this); } operator const rv<movable>&() const { return *reinterpret_cast<const rv<movable>* >(this); } private: int value_; public: movable() : value_(1){} //Move constructor and assignment movable(rv<movable>& m) { value_ = m.value_; m.value_ = 0; } movable & operator=(rv<movable>& m) { value_ = m.value_; m.value_ = 0; return *this; } bool moved() const //Observer { return value_ == 0; } }; movable function(movable m) { return movable(move(m)); } int main() { { movable m; movable m2(move(m)); assert(m.moved()); assert(!m2.moved()); } { movable m; movable m3(function(movable(move(m)))); assert(m.moved()); assert(!m3.moved()); } { movable m; movable m4(function(move(m))); assert(m.moved()); assert(!m4.moved()); } return 0; } -- Summary: Wrong code generated with -O2 and above Product: gcc Version: 4.4.4 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: eyakubovich at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44186
next reply other threads:[~2010-05-18 3:37 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-05-18 3:37 eyakubovich at gmail dot com [this message] 2010-05-18 3:50 ` [Bug c++/44186] " pinskia at gmail dot com 2010-05-18 3:50 ` [Bug c++/44186] New: " Andrew Pinski 2010-05-18 6:31 ` [Bug c++/44186] " pinskia at gcc dot gnu dot org 2010-05-18 9:26 ` paolo dot carlini at oracle dot com 2010-05-18 9:53 ` rguenth at gcc dot gnu dot org 2010-05-18 10:08 ` paolo dot carlini at oracle dot com
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-44186-19197@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).