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: RFC: -Wstrict-aliasing extension


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
help.

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

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk



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