variants: avoid type punning issue

This is based on what is recommended by both Scott Meyers, in 'Effective
C++', and Andrei Alexandrescu and Herb Sutter in 'C++ Coding Standards'.

Use a static_cast on void* rather than directly use a reinterpret_cast,
which can have nefarious effects on objects.  However, even though following
this guideline is good practice in general, I am not quite sure how relevant
it is when applied to conversions from POD to objects.  Actually, it might
very well be the opposite: isn't this exactly what reinterpret_cast is for?
What we really want *is* to transmit the memory map as a series of bytes,
which, if I am correct, falls into the kind of "low level" hack for which
this cast is meant.

In any case, this silences the warning, which will be greatly appreciated by
anyone using variants with a compiler supporting -fstrict-aliasing.

* data/variant.hh (as): Here.
* tests/c++.at (Exception safety, C++ Variant-based Symbols, Variants):
Don't use NO_STRICT_ALIAS_CXXFLAGS (revert commit ddb9db15), as type punning
is no longer an issue.
* tests/atlocal.in, configure.ac (NO_STRICT_ALIAS_CXXFLAGS): Remove
definition.
* examples/local.mk (NO_STRICT_ALIAS_CXXFLAGS): Remove from AM_CXXFLAGS.
* doc/bison.texi: Don't mention type punning issues.
This commit is contained in:
Theophile Ranquet
2013-01-29 22:35:04 +01:00
parent f29f8af3ed
commit be6fa942ac
6 changed files with 11 additions and 19 deletions

View File

@@ -10268,14 +10268,6 @@ therefore, since, as far as we know, @code{double} is the most demanding
type on all platforms, alignments are enforced for @code{double} whatever
types are actually used. This may waste space in some cases.
@item
Our implementation is not conforming with strict aliasing rules. Alias
analysis is a technique used in optimizing compilers to detect when two
pointers are disjoint (they cannot ``meet''). Our implementation breaks
some of the rules that G++ 4.4 uses in its alias analysis, so @emph{strict
alias analysis must be disabled}. Use the option
@option{-fno-strict-aliasing} to compile the generated parser.
@item
There might be portability issues we are not aware of.
@end itemize