mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
variants: prohibit simple copies
The "variant" structure provides a means to store, in a typeless way, C++ objects. Manipulating it without provide the type of the stored content is doomed to failure. So provide a means to copy in a type safe way, and prohibit typeless assignments. * data/c++.m4 (symbol_type::move): New. * data/lalr1.cc: Use it. * data/variant.hh (b4_variant_define): Provide variant::copy. Let variant::operator= abort. We cannot undefine it, yet, as it is still uses by the implicit assigment in symbols, which must also be disabled.
This commit is contained in:
@@ -79,6 +79,7 @@ m4_map([b4_char_sizeof_], [$@])dnl
|
||||
# The needed includes for variants support.
|
||||
m4_define([b4_variant_includes],
|
||||
[b4_parse_assert_if([[#include <typeinfo>]])[
|
||||
#include <cstdlib> // abort
|
||||
#ifndef YYASSERT
|
||||
# include <cassert>
|
||||
# define YYASSERT assert
|
||||
@@ -188,6 +189,15 @@ m4_define([b4_variant_define],
|
||||
other.destroy<T>();
|
||||
}
|
||||
|
||||
/// Copy the content of \a other to this.
|
||||
/// Destroys \a other.
|
||||
template <typename T>
|
||||
inline void
|
||||
copy (const variant<S>& other)
|
||||
{
|
||||
build<T> (other.as<T> ());
|
||||
}
|
||||
|
||||
/// Destroy the stored \a T.
|
||||
template <typename T>
|
||||
inline void
|
||||
@@ -198,6 +208,13 @@ m4_define([b4_variant_define],
|
||||
tname = YY_NULL;])[
|
||||
}
|
||||
|
||||
/// Prohibit blind copies.
|
||||
// private:
|
||||
self_type& operator=(const self_type&)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
|
||||
private:
|
||||
/// A buffer large enough to store any of the semantic values.
|
||||
/// Long double is chosen as it has the strongest alignment
|
||||
|
||||
Reference in New Issue
Block a user