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: [email protected]
ReportedBy: [email protected]
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 <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(...) {}
}
}