public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13881] New: pointer-to-data-member: rejects cast but allows comparision
@ 2004-01-27 10:19 smelkov at mph1 dot phys dot spbu dot ru
  2004-01-27 10:20 ` [Bug c++/13881] " smelkov at mph1 dot phys dot spbu dot ru
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: smelkov at mph1 dot phys dot spbu dot ru @ 2004-01-27 10:19 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-04-18 18:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-27 10:19 [Bug c++/13881] New: pointer-to-data-member: rejects cast but allows comparision smelkov at mph1 dot phys dot spbu dot ru
2004-01-27 10:20 ` [Bug c++/13881] " smelkov at mph1 dot phys dot spbu dot ru
2004-01-29  3:37 ` [Bug c++/13881] [3.3 Regression] Allow comparison between unrelated pointer-to-data-members giovannibajo at libero dot it
2004-01-29 12:26 ` smelkov at mph1 dot phys dot spbu dot ru
2004-01-29 16:38 ` giovannibajo at libero dot it
2004-02-02  9:19 ` smelkov at mph1 dot phys dot spbu dot ru
2004-02-15 12:41 ` gdr at gcc dot gnu dot org
2004-04-18 18:52 ` gdr at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).