mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
variant: fix G++ 4.4 warnings
The changes by Théophile Ranquet about type punning issues need to be extend to in-place new to please G++ 4.4.7. * data/variant.hh (variant::as_): New, factors the casts that avoid compiler warnings. (as, build): Use them.
This commit is contained in:
@@ -104,7 +104,7 @@ m4_define([b4_variant_define],
|
|||||||
: tname (typeid (T).name ())])[
|
: tname (typeid (T).name ())])[
|
||||||
{
|
{
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
new (buffer.raw) T (t);
|
new (as_ <T> ()) T (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destruction, allowed only if empty.
|
/// Destruction, allowed only if empty.
|
||||||
@@ -121,7 +121,7 @@ m4_define([b4_variant_define],
|
|||||||
YYASSERT (!tname);
|
YYASSERT (!tname);
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
tname = typeid (T).name ();])[
|
tname = typeid (T).name ();])[
|
||||||
return *new (buffer.raw) T;
|
return *new (as_<T> ()) T;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate a \a T in here from \a t.
|
/// Instantiate a \a T in here from \a t.
|
||||||
@@ -132,7 +132,7 @@ m4_define([b4_variant_define],
|
|||||||
YYASSERT (!tname);
|
YYASSERT (!tname);
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
tname = typeid (T).name ();])[
|
tname = typeid (T).name ();])[
|
||||||
return *new (buffer.raw) T (t);
|
return *new (as_<T> ()) T (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Accessor to a built \a T.
|
/// Accessor to a built \a T.
|
||||||
@@ -142,10 +142,7 @@ m4_define([b4_variant_define],
|
|||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (tname == typeid (T).name ());
|
YYASSERT (tname == typeid (T).name ());
|
||||||
YYASSERT (sizeof (T) <= S);])[
|
YYASSERT (sizeof (T) <= S);])[
|
||||||
{
|
return *as_<T> ();
|
||||||
void *dummy = buffer.raw;
|
|
||||||
return *static_cast<T*> (dummy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Const accessor to a built \a T (for %printer).
|
/// Const accessor to a built \a T (for %printer).
|
||||||
@@ -155,10 +152,7 @@ m4_define([b4_variant_define],
|
|||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (tname == typeid (T).name ());
|
YYASSERT (tname == typeid (T).name ());
|
||||||
YYASSERT (sizeof (T) <= S);])[
|
YYASSERT (sizeof (T) <= S);])[
|
||||||
{
|
return *as_<T> ();
|
||||||
const void *dummy = buffer.raw;
|
|
||||||
return *static_cast<const T*> (dummy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Swap the content with \a other, of same type.
|
/// Swap the content with \a other, of same type.
|
||||||
@@ -213,6 +207,24 @@ m4_define([b4_variant_define],
|
|||||||
self_type& operator=(const self_type&);
|
self_type& operator=(const self_type&);
|
||||||
variant (const self_type&);
|
variant (const self_type&);
|
||||||
|
|
||||||
|
/// Accessor to raw memory as \a T.
|
||||||
|
template <typename T>
|
||||||
|
T*
|
||||||
|
as_ ()
|
||||||
|
{
|
||||||
|
void *yyp = buffer.raw;
|
||||||
|
return static_cast<T*> (yyp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Const accessor to raw memory as \a T.
|
||||||
|
template <typename T>
|
||||||
|
const T*
|
||||||
|
as_ () const
|
||||||
|
{
|
||||||
|
const void *yyp = buffer.raw;
|
||||||
|
return static_cast<const T*> (yyp);
|
||||||
|
}
|
||||||
|
|
||||||
/// A buffer large enough to store any of the semantic values.
|
/// A buffer large enough to store any of the semantic values.
|
||||||
/// Long double is chosen as it has the strongest alignment
|
/// Long double is chosen as it has the strongest alignment
|
||||||
/// constraints.
|
/// constraints.
|
||||||
|
|||||||
Reference in New Issue
Block a user