[Bug optimization/12484] New: virtual function yields bogus value when returning float constant (-O3 -fPIC)
jonathan at cdnorthamerica dot com
gcc-bugzilla@gcc.gnu.org
Wed Oct 1 19:00:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12484
Summary: virtual function yields bogus value when returning float
constant (-O3 -fPIC)
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jonathan at cdnorthamerica dot com
CC: gcc-bugs at gcc dot gnu dot org
here's the code to reproduce the error...
//----
#include <iostream>
class Foo
{
public:
Foo() : _value(1) {}
virtual ~Foo() {}
virtual float getValue() const { return float(1); }
virtual float getMemberValue() const { return _value; }
private:
float const _value;
};
void
useFoo(Foo const &f)
{
std::cout << std::endl
<< "Foo const &f; "
<< std::endl;
std::cout << " f.getValue() = "
<< f.getValue()
<< std::endl;
std::cout << " f.getMemberValue() = "
<< f.getMemberValue()
<< std::endl;
}
int
main()
{
Foo foo;
std::cout << std::endl
<< "Foo foo; "
<< std::endl;
std::cout << " foo.getValue() = "
<< foo.getValue()
<< std::endl;
std::cout << " foo.getMemberValue() = "
<< foo.getMemberValue()
<< std::endl;
useFoo(foo);
}
//---
note:
1) problem occurs with -O3 and -fPI; dropping to -O2 and/or omitting -fPIC
eliminates problem
2) bogus results occur only when returning constant (e.g. return float(1); );
returning member data is o.k. (e.g. return _value)
3) bogus results occur only when given const reference to object having virtual
member; seems to work o.k. given the object itself
4) g++ 3.3.1 gives same behavior
More information about the Gcc-bugs
mailing list