[Bug middle-end/64642] Malformed code as result of C-cast to (polymorphic) object-reference (depends on opt-level ...)

meisenmann.lba@fh-salzburg.ac.at gcc-bugzilla@gcc.gnu.org
Mon Jan 19 19:17:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64642

--- Comment #2 from Markus Eisenmann <meisenmann.lba@fh-salzburg.ac.at> ---
I do not (completely) agree, that the code/result is undefined. Of course, this
sample doesn’t make any sense and shouldn’t never occur (in a similar form).

But - in this case - the C-style cast, like
    A& ref = (A&) arg;
is a “interpreted” as *):
    A& ref = *reinterpret_cast<A*>(&arg);

*) As (IMHO) described in C++ Standard (2003).

Assuming, that arg is passed on stack (Ie. Memory), the code seems to be valid.
If the passed value (itself) points to valid code (and based on the
vtable-layout) it’s may be a valid (sub-) call.

At least, I’ve wondered about the optimizer-result; regardless, whether it
makes sense and compared/based to my understanding of the C++ Standard (or
earlier GCC-releases or other C++-compilers).


More information about the Gcc-bugs mailing list