This is the mail archive of the
mailing list for the GCC project.
Re: RFC: -Wstrict-aliasing extension
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Jim Wilson <wilson at specifixinc dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 01 Mar 2004 10:12:53 +0000
- Subject: Re: RFC: -Wstrict-aliasing extension
- Organization: Codesourcery LLC
- References: <email@example.com>
Jim Wilson wrote:
A customer moving from gcc-2.9x to gcc-3.x ran into problems with
-fstrict-aliasing, and was disappointed that -Wstrict-aliasing did not
The problem is that -Wstrict-aliasing does not warn about ambiguous
cases. If you have a structure that contains a char in addition to
other types, then it is valid to cast a pointer to the structure type
and dereference the char, but not valid to dereference one of the other
types. Since a cast to this structure type might be valid, the current
-Wstrict-aliasing code gives no warning at all. However, this makes it
impossible for users to find some of their invalid code.
I wrote a patch that warns for the ambiguous cases, adding "may" to the
message, to indicate that the code may or may not be OK. This allowed
the customer to find the problems in their code.
IMHO 'might' is better than 'may'
1) the earlier warning with incomplete type type punning uses 'might'
2) 'may' is generally ambigous, does it mean 'might happen' or does it
mean 'has permission to happen'? I think it pedantically means the latter,
hence the difference in meaning of 'I may write a program',
'I can write a program', and 'I might write a program' :)
As to 'type-punning' perhaps 'type-punning via pointer casting'. I
thought it was a generally well known phrase.
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
firstname.lastname@example.org :: http://www.planetfall.pwp.blueyonder.co.uk