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] New: pointer-to-data-member: rejects cast but allows comparision


It is possible to compare 'A C::*' with 'B C::*' (B inherits from A) 
while cast from 'B C::*' to 'A C::*' is rejected. 
 
I used to think that member pointers have same semantics when bound, 
so if 'B*' can be casted to 'A*', someone might expect that 'B C::*' can be casted to 'A C::*' 
(for example for plain non-virtual data-members). 
 
see code below. 
 
--- 
class A {}; 
class B : public A {}; 
 
class C { 
public: 
    A a; 
    B b; 
}; 
 
int main() 
{ 
    A C::*  memptr_a  =  &C::a;         // ok 
    B C::*  memptr_b  =  &C::b;         // ok 
 
    if (memptr_a == memptr_b)           // ok 
        return 1; 
 
    if (&C::a == &C::b)                 // ok 
        return 1; 
 
    // but the following produce errors: 
 
    // error: invalid conversion from `B C::*' to `A C::*' 
    memptr_a = memptr_b; 
 
    // error: invalid conversion from `B C::*' to `A C::*' 
    A C::*  memptr_a2  = &C::b; 
 
    return 0; 
} 
--- 
 
By the way: icc rejects comparision of 'A C::*' with 'B C::*' 
so this bug is about 
- 'invalid code accepted' (allows comparision), or 
- 'valid code rejected' (rejects casting) 
 
 
Can someone shed light on this subject? 
 
-- 
	Kirill.

-- 
           Summary: pointer-to-data-member: rejects cast but allows
                    comparision
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: smelkov at mph1 dot phys dot spbu dot ru
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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]