This is the mail archive of the cygwin-developers@cygwin.com mailing list for the Cygwin 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]

Re: Many pthread failures in the test suite, one setgroup failure


On Mon, 2002-09-30 at 16:43, egor duda wrote:
> Hi!
> 
> Sunday, 29 September, 2002 Robert Collins rbcollins@cygwin.com wrote:
> 
> >> Now, in verifyable_object_isvalid you're casing pointer to variable of
> >> subclass to pointer to base class. Ain't it case of 'never do like
> >> this'? I suppose to safely perform cast from subclass to base class
> >> one should always use dynamic_cast().
> 
> RC> It's a case of this is always ways ok to do - upcasting is FINE.. (it
> RC> happens every time you call a virtual function in fact).
> 
> Yes, it's fine as long as it's done via compiler. When virtual
> function is called it's compiler duty to arrange things so that this
> is pointing to the proper place in memory. The same for dynamic_cast,
> compiler knows how to update pointer. But what's done in
> verifyable_object_isvalid() is _not_ upcasting. It's essentially a
> pointer arithmetic. And i bet it's not guaranteed to work -- it will
> obviously fail in the case of multiple inheritance when class C is
> derived from class A and class B, and clearly, you won't be able to do
> the trick with pointer assignments to cast pointer to the instance of
> class C to both class A and class B. You'll need to use compiler
> knowledge about class C instance layout for either casting to class A
> or class B. So, the safe way is to always use dynamic_cast (or virtual
> functions) and let compiler to arrange everything.

The main reason it's not guaranteed in my code is that we are using void
* tricks at the moment - I agree with you there.
Secondly, we are not calling generic methods, but static methods, which
means if we tell the compiler that we will pass (say) verifyable_object
** to the static method, then it should be able to upcast safely. I'm
not sure what the spec has to say about upcasting from a foo ** pointer
though.
 
> Which bug in gcc? I guess we should look into C++ standard first. But
> i suspect it doesn't say anything about offsets for common members in
> base and derived classes being always equal, so that programmer can do
> pointer assignment to cast from base to derived and vice versa. As i
> said, it wouldn't be true in at least one case -- multiple
> inheritance. So, before qualifying this as a gcc bug, you should first
> give an appropriate reference to the standard.

Oh, absolutely. If I couldn't generate an in-spec test case, I wouldn't
raise anything as a bug.

Rob

-- 
---
GPG key available at: http://users.bigpond.net.au/robertc/keys.txt.
---

Attachment: signature.asc
Description: This is a digitally signed message part


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