[cfe-dev] type-punning warnings for CXXTypeidExpr::child_begin()/child_end()

Eli Friedman eli.friedman at gmail.com
Wed Dec 3 14:11:51 PST 2008


On Wed, Dec 3, 2008 at 1:28 PM, Ted Kremenek <kremenek at apple.com> wrote:
> In ExprCXX.cpp I see:
>
> Stmt::child_iterator CXXTypeidExpr::child_begin() {
>   return isTypeOperand() ? child_iterator() : (Stmt**)&Operand;
> }
>
> The expression '(Stmt**)&Operand' leads to type-punning warnings
> during a Release build.  This looks like a real issue to me.  Is this
> safe, or do we need to fix it?  The same warning appears in child_end().

It looks like a real issue to me too.  I guess the simplest solution
is to change "void *Operand;" to "union {void* Operand; Stmt*
OperandExpr;};", and change child_begin to use OperandExpr.  It isn't
pretty, but I think it has the intended semantics.

I guess it's worth noting that SizeOfAlignOfExpr has the same issue.

-Eli



More information about the cfe-dev mailing list