Hi,
I have been testing out some example programs from the variant tutorial.
First, I ran across some errors in the code shown in the documentation
for the "first variant program."
(From GCC 2.95.2)
ex1.cpp:17: `which' undeclared (first use this function)
ex1.cpp:48: `a_printer' undeclared (first use this function)
ex1.cpp:48: `inst' undeclared (first use this function)
ex1.cpp:41: warning: unused variable `struct printer print'
In addition, compiling with Intel C++ 7.0 under strict ansi compliance
(-ansi) revealed the following nits as well:
aligned_storage.hpp(70):
error #308: type "boost::aligned_storage<size_, alignment_>::align_t [with
size_=28U, alignment_=4U]" is inaccessible
(I believe this is because the nested classes/unions have no special
access to private members of the enclosing class.
I added a friend declaration and union declaration to fix this.
boost/variant.hpp(1010): error #308: function "boost::variant<A, B, T0,
T1, T2, T3, T4, T5, T6, T7>::inactive_storage [with A=std::string, B=char
*, T0=int, T1=boost::detail::variant::void_,
T2=boost::detail::variant::void_, T3=boost::detail::variant::void_,
T4=boost::detail::variant::void_, T5=boost::detail::variant::void_,
T6=boost::detail::variant::void_, T7=boost::detail::variant::void_]" is
inaccessible
new(target_.inactive_storage()) T(operand);
^
(followed by many more of the same)
I added a class declaration prior to the friend class declaration for
the class "assign_into;" (on line 963 of variant.hpp)
aligned_storage.hpp: warning about the change of sign on
alignment_ == -1.
I got this warning from Gnu C++ as well. I Added a cast to silence
compiler warnings:
alignment_ == (std::size_t)-1.
boost/variant.hpp(673): warning #191: type qualifier is meaningless on
cast type
return const_cast<variant * const>(this)->active_storage();
I removed const from expression.
I've enclosed patches (unified diffs) for these.
Cheers,
ron
--- aligned_storage.hpp Thu Feb 13 17:05:18 2003
+++ aligned_storage.hpp.2 Fri Feb 21 09:45:31 2003
@@ -38,13 +38,13 @@
template <
std::size_t size_
- , std::size_t alignment_ = -1
+ , std::size_t alignment_ = (std::size_t)-1
>
class aligned_storage
{
private:
typedef typename mpl::apply_if_c<
- alignment_ == -1
+ alignment_ == (std::size_t)-1
, mpl::identity<detail::max_align>
, type_with_alignment<alignment_>
>::type align_t;
@@ -57,13 +57,15 @@
BOOST_STATIC_CONSTANT(
std::size_t
, alignment = (
- alignment_ == -1
+ alignment_ == (std::size_t)-1
? detail::alignment_of_max_align
: alignment_
)
);
private: // representation
+ union data_t;
+ friend union data_t;
union data_t
{
char buf[size];
--- variant.hpp Fri Feb 14 15:38:38 2003
+++ variant.hpp.2 Fri Feb 21 09:51:38 2003
@@ -561,7 +561,7 @@
, mpl::logical_and<
mpl::is_sequence<A>
, mpl::equal_to<
- detail::variant::mpl::guarded_size<A, min_list_size>
+ mpl::guarded_size<A, min_list_size>
, min_list_size
>
>
@@ -670,7 +670,7 @@
const void* active_storage() const
{
- return const_cast<variant * const>(this)->active_storage();
+ return const_cast<variant *>(this)->active_storage();
}
void* inactive_storage()
@@ -960,6 +960,7 @@
// given, maintaining the strong guarantee of exception safety.
//
+ class assign_into;
friend class assign_into;
class assign_into
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost