[cfe-dev] new warnings

Mike Stump mrs at apple.com
Thu Sep 25 19:39:04 PDT 2008


On Sep 25, 2008, at 4:47 PM, Ted Kremenek wrote:
> Any suggestion on how to fix this?  We're basically using the field  
> as a variant, this it is perfectly safe (I believe).

class DeclGroupRef {
   uintptr_t ThePtr;


   iterator begin() {
     if (getKind() == DeclKind)
       return ThePtr ? (Decl**) &ThePtr : 0;

?  You think that is safe?  Why?  I don't see any unions, I don't see  
any memcpys, no character types.

Let me put is plainly, you can't access a type as another type and  
expect it to work.  There are a couple exceptions to this, and if you  
want to make use of them, you have to know which one it is and meet  
the requirements for it.  Which exception were you trying to make use  
of:

        [#7] An object shall have its stored value accessed only  by
        an lvalue expression that has one of the following types:61)

          -- a  type  compatible  with  the  effective  type  of the
             object,

          -- a qualified version  of  a  type  compatible  with  the
             effective type of the object,

          -- a   type   that   is   the   signed  or  unsigned  type
             corresponding to the effective type of the object,

          -- a  type  that  is   the   signed   or   unsigned   type
             corresponding  to  a qualified version of the effective
             type of the object,

          -- an aggregate or union type that  includes  one  of  the
             aforementioned  types  among  its  members  (including,
             recursively, a member of a  subaggregate  or  contained
             union), or

          -- a character type.


?  [ toquote the the C rules, as my fingers for some reason didn't  
find the C++ rules in seconds ]

If you want to do math on a pointer, convert to uintptr_t and then do  
the math, that's safe.



More information about the cfe-dev mailing list