mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
c++: variants: comparing addresses of typeid.name() is undefined
Instead of storing and comparing pointers to names of types, store pointers to the typeids, and compares the typeids. Reported by Thomas Jahns. <http://lists.gnu.org/archive/html/bug-bison/2014-03/msg00001.html> * data/variant.hh (yytname_): Replace with... (yytypeid_): this.
This commit is contained in:
1
THANKS
1
THANKS
@@ -132,6 +132,7 @@ Steve Murphy murf@parsetree.com
|
|||||||
Sum Wu sum@geekhouse.org
|
Sum Wu sum@geekhouse.org
|
||||||
Théophile Ranquet theophile.ranquet@gmail.com
|
Théophile Ranquet theophile.ranquet@gmail.com
|
||||||
Thiru Ramakrishnan thiru.ramakrishnan@gmail.com
|
Thiru Ramakrishnan thiru.ramakrishnan@gmail.com
|
||||||
|
Thomas Jahns jahns@dkrz.de
|
||||||
Tim Josling tej@melbpc.org.au
|
Tim Josling tej@melbpc.org.au
|
||||||
Tim Landscheidt tim@tim-landscheidt.de
|
Tim Landscheidt tim@tim-landscheidt.de
|
||||||
Tim Van Holder tim.van.holder@pandora.be
|
Tim Van Holder tim.van.holder@pandora.be
|
||||||
|
|||||||
@@ -95,13 +95,13 @@ m4_define([b4_variant_define],
|
|||||||
|
|
||||||
/// Empty construction.
|
/// Empty construction.
|
||||||
variant ()]b4_parse_assert_if([
|
variant ()]b4_parse_assert_if([
|
||||||
: yytname_ (YY_NULLPTR)])[
|
: yytypeid_ (YY_NULLPTR)])[
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/// Construct and fill.
|
/// Construct and fill.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
variant (const T& t)]b4_parse_assert_if([
|
variant (const T& t)]b4_parse_assert_if([
|
||||||
: yytname_ (typeid (T).name ())])[
|
: yytypeid_ (&typeid (T))])[
|
||||||
{
|
{
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
new (yyas_<T> ()) T (t);
|
new (yyas_<T> ()) T (t);
|
||||||
@@ -110,7 +110,7 @@ m4_define([b4_variant_define],
|
|||||||
/// Destruction, allowed only if empty.
|
/// Destruction, allowed only if empty.
|
||||||
~variant ()
|
~variant ()
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (!yytname_);
|
YYASSERT (!yytypeid_);
|
||||||
])[}
|
])[}
|
||||||
|
|
||||||
/// Instantiate an empty \a T in here.
|
/// Instantiate an empty \a T in here.
|
||||||
@@ -118,9 +118,9 @@ m4_define([b4_variant_define],
|
|||||||
T&
|
T&
|
||||||
build ()
|
build ()
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (!yytname_);
|
YYASSERT (!yytypeid_);
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
yytname_ = typeid (T).name ();])[
|
yytypeid_ = & typeid (T);])[
|
||||||
return *new (yyas_<T> ()) T;
|
return *new (yyas_<T> ()) T;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,9 +129,9 @@ m4_define([b4_variant_define],
|
|||||||
T&
|
T&
|
||||||
build (const T& t)
|
build (const T& t)
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (!yytname_);
|
YYASSERT (!yytypeid_);
|
||||||
YYASSERT (sizeof (T) <= S);
|
YYASSERT (sizeof (T) <= S);
|
||||||
yytname_ = typeid (T).name ();])[
|
yytypeid_ = & typeid (T);])[
|
||||||
return *new (yyas_<T> ()) T (t);
|
return *new (yyas_<T> ()) T (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ m4_define([b4_variant_define],
|
|||||||
T&
|
T&
|
||||||
as ()
|
as ()
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytname_ == typeid (T).name ());
|
YYASSERT (*yytypeid_ == typeid (T));
|
||||||
YYASSERT (sizeof (T) <= S);])[
|
YYASSERT (sizeof (T) <= S);])[
|
||||||
return *yyas_<T> ();
|
return *yyas_<T> ();
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ m4_define([b4_variant_define],
|
|||||||
const T&
|
const T&
|
||||||
as () const
|
as () const
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytname_ == typeid (T).name ());
|
YYASSERT (*yytypeid_ == typeid (T));
|
||||||
YYASSERT (sizeof (T) <= S);])[
|
YYASSERT (sizeof (T) <= S);])[
|
||||||
return *yyas_<T> ();
|
return *yyas_<T> ();
|
||||||
}
|
}
|
||||||
@@ -167,8 +167,8 @@ m4_define([b4_variant_define],
|
|||||||
void
|
void
|
||||||
swap (self_type& other)
|
swap (self_type& other)
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytname_);
|
YYASSERT (yytypeid_);
|
||||||
YYASSERT (yytname_ == other.yytname_);])[
|
YYASSERT (*yytypeid_ == *other.yytypeid_);])[
|
||||||
std::swap (as<T> (), other.as<T> ());
|
std::swap (as<T> (), other.as<T> ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +198,7 @@ m4_define([b4_variant_define],
|
|||||||
destroy ()
|
destroy ()
|
||||||
{
|
{
|
||||||
as<T> ().~T ();]b4_parse_assert_if([
|
as<T> ().~T ();]b4_parse_assert_if([
|
||||||
yytname_ = YY_NULLPTR;])[
|
yytypeid_ = YY_NULLPTR;])[
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -233,7 +233,7 @@ m4_define([b4_variant_define],
|
|||||||
} yybuffer_;]b4_parse_assert_if([
|
} yybuffer_;]b4_parse_assert_if([
|
||||||
|
|
||||||
/// Whether the content is built: if defined, the name of the stored type.
|
/// Whether the content is built: if defined, the name of the stored type.
|
||||||
const char *yytname_;])[
|
const std::type_info *yytypeid_;])[
|
||||||
};
|
};
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user