This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13881] [3.3 Regression] Allow comparison between unrelated pointer-to-data-members


------- Additional Comments From giovannibajo at libero dot it  2004-01-29 16:38 -------
Subject: Re:  [3.3 Regression] Allow comparison between unrelated pointer-to-data-members

smelkov at mph1 dot phys dot spbu dot ru wrote:

> A and B is related types (A is base of B), hence B* can be casted to
> A*. As to 'A C::*' and 'B C::*' they are pointers to A & B objects in
> specific scope (C class) --- i think they are related too.

No, because they're basically offsets to A and B objects in C scope. Until
they're *bound* to a specific object, they don't allow any standard conversion
besides the one that I explained you. After you bind them (through
"operator ->*" or "operator .*"), they become regular A* or B*, and you can do
whatever you want.

> C c;
>
> A C::*  mem_pa;
> B C::*  mem_pb;
>
> pa = &c.a; // ok
> pb = &c.b; // ok
> pa = &c.b; // !!! this is also correct!!!

of course, because &c.b is a regular B*.

> mem_pa = &C::a; // ok
> mem_pb = &C::b; // ok
>
> mem_pa = &C::b; // ?wrong?

Yes, because the types don't match and there is no standard conversion that
applies.

> All i'm saying about is possible, but is not implemented for now.

The point is not what a compiler could do, but what it has to do. ISO C++
Standard forbids such conversions, and g++ won't allow them. Your report has
been useful since it made us discover an accepts-invalid on the 3.3 branch, so
that we can probably backport the fix and have it fixed for 3.3.4. g++ since
3.4.0 already implements the correct behaviour though.

I think you're using the wrong approach, hence the problems you're facing. If
you need some powerful and generic mechanism for function dispatch or object
visits, look into boost::function.

Giovanni Bajo




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13881


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]