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] Add a -Wcast-align=strict warning


On 09/13/17 19:06, Joseph Myers wrote:
> What does this warning do in cases where a type has different alignments
> inside and outside structs?  I'm thinking of something like
> 
> struct s { long long x; } *p;
> /* ... */
> (long long *)p
> 
> on 32-bit x86 - where long long's preferred alignment is 8 bytes, but in
> structures it's 4 bytes.  (Likewise for double in place of long long.)  I
> think a warning for a (long long *)p cast might be surprising in that
> case.
> 

Well, yes this does get a warning.  But doesn't that cast then violate
the underlying alignment requirement of long long* ?

Of course there is probably a reason why -Wcast-align is not enabled by
default, and likewise this warning emits a fair amount of false
positives, but nevertheless I think it is often worth looking at the
places where this warning flags a possible alignment issue.

However, neither -Wcast-align nor -Wcast-align=strict are enabled unless
explicitly requested.


Bernd.

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