This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: const and strict aliasing rules
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: jlkjr at bioleap dot com (John L. Kulp), gcc at gcc dot gnu dot org
- Date: 05 Dec 2006 01:17:05 +0100
- Subject: Re: const and strict aliasing rules
- References: <200612042359.kB4NxJC6002962@localhost.localdomain>
Andrew Pinski <pinskia@physics.uc.edu> writes:
| > You can work around this by using union's of pointers of both non-const
| > and const types, but the reinterpret_cast solution would be more attractive.
| >
| > Thoughts?
|
| This has nothing to do with const vs non-const but rather
| a<int> and a<const int> are two seperate types which are not related in any way.
| The C++ standard defines these two types as seperate types and are not compatiable
| in any way for aliasing.
???
3.10/15:
If a program attempts to access the stored value of an object
through an lvalue of other than one of the following types the
behavior is undefined48):
-- the dynamic type of the object,
-- *a cv-qualified version of the dynamic type of the object*,
-- a type that is the signed or unsigned type corresponding to the
dynamic type of the object,
-- a type that is the signed or unsigned type corresponding to a
cv-qualified version of the dynamic 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),
-- a type that is a (possibly cv-qualified) base class type of the
dynamic type of the object,
-- a char or unsigned char type.
-- Gaby