
Hi all, after banging my head for an entire day I come out with this test case showing a possible bug in gcc 4.4.3 or in boost optional, the test crashes with a pure virtual method called only if compiled only with -O1, -O2, -O3. The same code in another machine with gcc 4.7.2 and boost 1.49 works fine. Regards Gaetano Mendola #include <boost/optional.hpp> #include <boost/noncopyable.hpp> 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<size_t> 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(...) {} } }