summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim@lrde.epita.fr>2015-01-07 10:24:53 +0100
committerAkim Demaille <akim@lrde.epita.fr>2015-01-07 10:34:07 +0100
commit7cf84b13a079740a638fed6b46634bc888bd2622 (patch)
tree1be656e7e75ec316c6ab1b53148bcff4dc68bb0a
parent56351d4c7b3be8a81953defa7e34503976d3589b (diff)
downloadbison-7cf84b13a079740a638fed6b46634bc888bd2622.tar.gz
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.
-rw-r--r--THANKS1
-rw-r--r--data/variant.hh26
2 files changed, 14 insertions, 13 deletions
diff --git a/THANKS b/THANKS
index 2436f004..908498c7 100644
--- a/THANKS
+++ b/THANKS
@@ -132,6 +132,7 @@ Steve Murphy murf@parsetree.com
Sum Wu sum@geekhouse.org
Théophile Ranquet theophile.ranquet@gmail.com
Thiru Ramakrishnan thiru.ramakrishnan@gmail.com
+Thomas Jahns jahns@dkrz.de
Tim Josling tej@melbpc.org.au
Tim Landscheidt tim@tim-landscheidt.de
Tim Van Holder tim.van.holder@pandora.be
diff --git a/data/variant.hh b/data/variant.hh
index 78c2f945..f918e34c 100644
--- a/data/variant.hh
+++ b/data/variant.hh
@@ -95,13 +95,13 @@ m4_define([b4_variant_define],
/// Empty construction.
variant ()]b4_parse_assert_if([
- : yytname_ (YY_NULLPTR)])[
+ : yytypeid_ (YY_NULLPTR)])[
{}
/// Construct and fill.
template <typename T>
variant (const T& t)]b4_parse_assert_if([
- : yytname_ (typeid (T).name ())])[
+ : yytypeid_ (&typeid (T))])[
{
YYASSERT (sizeof (T) <= S);
new (yyas_<T> ()) T (t);
@@ -110,7 +110,7 @@ m4_define([b4_variant_define],
/// Destruction, allowed only if empty.
~variant ()
{]b4_parse_assert_if([
- YYASSERT (!yytname_);
+ YYASSERT (!yytypeid_);
])[}
/// Instantiate an empty \a T in here.
@@ -118,9 +118,9 @@ m4_define([b4_variant_define],
T&
build ()
{]b4_parse_assert_if([
- YYASSERT (!yytname_);
+ YYASSERT (!yytypeid_);
YYASSERT (sizeof (T) <= S);
- yytname_ = typeid (T).name ();])[
+ yytypeid_ = & typeid (T);])[
return *new (yyas_<T> ()) T;
}
@@ -129,9 +129,9 @@ m4_define([b4_variant_define],
T&
build (const T& t)
{]b4_parse_assert_if([
- YYASSERT (!yytname_);
+ YYASSERT (!yytypeid_);
YYASSERT (sizeof (T) <= S);
- yytname_ = typeid (T).name ();])[
+ yytypeid_ = & typeid (T);])[
return *new (yyas_<T> ()) T (t);
}
@@ -140,7 +140,7 @@ m4_define([b4_variant_define],
T&
as ()
{]b4_parse_assert_if([
- YYASSERT (yytname_ == typeid (T).name ());
+ YYASSERT (*yytypeid_ == typeid (T));
YYASSERT (sizeof (T) <= S);])[
return *yyas_<T> ();
}
@@ -150,7 +150,7 @@ m4_define([b4_variant_define],
const T&
as () const
{]b4_parse_assert_if([
- YYASSERT (yytname_ == typeid (T).name ());
+ YYASSERT (*yytypeid_ == typeid (T));
YYASSERT (sizeof (T) <= S);])[
return *yyas_<T> ();
}
@@ -167,8 +167,8 @@ m4_define([b4_variant_define],
void
swap (self_type& other)
{]b4_parse_assert_if([
- YYASSERT (yytname_);
- YYASSERT (yytname_ == other.yytname_);])[
+ YYASSERT (yytypeid_);
+ YYASSERT (*yytypeid_ == *other.yytypeid_);])[
std::swap (as<T> (), other.as<T> ());
}
@@ -198,7 +198,7 @@ m4_define([b4_variant_define],
destroy ()
{
as<T> ().~T ();]b4_parse_assert_if([
- yytname_ = YY_NULLPTR;])[
+ yytypeid_ = YY_NULLPTR;])[
}
private:
@@ -233,7 +233,7 @@ m4_define([b4_variant_define],
} yybuffer_;]b4_parse_assert_if([
/// Whether the content is built: if defined, the name of the stored type.
- const char *yytname_;])[
+ const std::type_info *yytypeid_;])[
};
]])