This is the mail archive of the gcc-patches@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: Patch: New implementation of -Wstrict-aliasing


Silvius Rus <rus@google.com> writes:

[...]

| > There should be a warning for g
| > ++.dg/warn/Wstrict-aliasing-bogus-union.C union U {
| >   int i;
| >   float f;
| > };
| > float g(int *a, float *b)
| > {
| >   *a = 1;
| >   return *b;
| > }
| >
| > float foo () {
| >   union U u;
| >   return g(&u.i, &u.f);
| > }
| >
| > The above code is undefined, even though unions are "holly" in GCC.
| >
| >
| Should we warn based on the standard rather than on what GCC
| guarantees? 

Both -- in fact the latter, since it contains the former.

| Maybe we should not give unions a special treatment just
| for the purposes of the warning, since this could cause much trouble
| when porting code to other compilers.

There is a distinctive difference here.  Because of the aliaing issue,
GCC has documented that it will always honor the union trick;
consequently, warning about that construct might be considered
inappropriate.   If that really is an issue, then warn about it only
if -pedantic and the construct is not inside a __extension__ -- but
I'm sure some people would find it very pedantic.

-- Gaby


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