This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add a -Wcast-align=strict warning
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Nathan Sidwell <nathan at acm dot org>, Jason Merrill <jason at redhat dot com>, Marek Polacek <polacek at redhat dot com>
- Date: Wed, 13 Sep 2017 19:52:38 +0000
- Subject: Re: [PATCH] Add a -Wcast-align=strict warning
- Authentication-results: sourceware.org; auth=none
- Authentication-results: codesourcery.com; dkim=none (message not signed) header.d=none;codesourcery.com; dmarc=none action=none header.from=hotmail.de;
- References: <AM5PR0701MB26571284440889EF6AFF47B8E4910@AM5PR0701MB2657.eurprd07.prod.outlook.com> <alpine.DEB.2.20.1709131701160.29579@digraph.polyomino.org.uk>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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.