This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/53225] static operator new in multiple inheritance carries incorrect type information for the class
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 04 May 2012 21:06:34 +0000
- Subject: [Bug c++/53225] static operator new in multiple inheritance carries incorrect type information for the class
- Auto-submitted: auto-generated
- References: <bug-53225-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53225
--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-04 21:06:34 UTC ---
Also, see the code I provided at SO:
http://stackoverflow.com/a/10449212/981959
That demonstrates that a base class member function knows nothing about the
derived class.
here's another:
#include <iostream>
void g(int i) { std::cout << "int: " << i << '\n'; }
void g(short i) { std::cout << "short: " << i << '\n'; }
struct A
{
static const int i = 1;
typedef int int_type;
void f() {
int_type j = i;
g(j);
}
};
struct B : A
{
static const short i = 0;
typedef short int_type;
};
int main()
{
B b;
b.f();
}
A::f() calls g(int) and prints 1, not g(short) printing 0, because in A::f()
int_type is int and i has the value 1.
That's a normal member function, not operator new. You could make A::f()
static and the result will be exactly the same.
Does that help?