From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21310 invoked by alias); 23 Nov 2012 15:44:27 -0000 Received: (qmail 21281 invoked by uid 48); 23 Nov 2012 15:44:10 -0000 From: "mendola at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55449] New: [4.4.3] pure virtual call only with -O1/2/3 (boost::optional) Date: Fri, 23 Nov 2012 15:44:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: mendola at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02194.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55449 Bug #: 55449 Summary: [4.4.3] pure virtual call only with -O1/2/3 (boost::optional) Classification: Unclassified Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: mendola@gmail.com Created attachment 28765 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28765 test case + preprocessor output The following code generates a pure virtual method call only when compiled with -O1/O2/O3, the same code seems working without error with gcc 4.7.3. The code is inlined in here and I have attached an archive containing the preprocessor output as well. Consider that it doesn't crash if: - Remove the noncopyable from B or - Remove one of the two segments in the extra scope in main or - Remove the try { } catch I have tried with boost 1.40, 1.50 and 1.52 #include #include class B : boost::noncopyable { //if the noncopyable is removed works public: virtual size_t bar() const = 0; }; class D : public B { public: D() :theBar(foo(10)) { } virtual size_t bar() const { return theBar; } private: static size_t foo(const boost::optional a) { if (a) { //if this is a.is_initialized() then it works return a.get(); } return 2; } const size_t theBar; }; class Foo { public: Foo(const B& b) :theBar(b.bar() * b.bar()) { } private: const size_t theBar; }; int main() { { //if this section is removed works D d; try { Foo myCompound(d); } catch(...) {} } { D d; try { Foo myCompound(d); } catch(...) {} } }