This is the mail archive of the gcc-help@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]

Re: Reference to pointer and cast - is this a bug ?


Hi Philippe,

> If this is a bug, I did not find it in the bug database.
> If not, can anybody tell me why ?

Not a bug.

A child is a parent.

A child pointer, itself, is a type.
A parent pointer, itself, is a type.

A child pointer is not a parent pointer.

Put ten more trace(c_ptr_r); in your source.  Notice that each one has a
different address.  Anonymous variables are being created - anonymous
variables that have a different type.

Take out the const part of the const& to trace, and you'll notice that the
compiler indicates that is an error - because a child pointer is not a
parent pointer.

Since you used a const&, the child pointer will be treated as if it is a
parent pointer (via the magic of the anonymous variable introduced and
implicit conversion).

The trace statement is printing the address of the anonymous variable, which
is why it differs.

May have something to do with the scaffolding for the SSA optimization, even
in non-optimized code (-O0).

HTH,
--Eljay



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