Fixes for Ticket #7569 ( Compile Error using BOOST_FUSION_DEFINE_STRUCT_INLINE with VC10 and GCC <4.5 )

[SVN r81165]
This commit is contained in:
Joel de Guzman
2012-11-04 00:18:41 +00:00
parent d01148d339
commit cfbbba272e
3 changed files with 183 additions and 39 deletions

View File

@ -8,6 +8,7 @@
#ifndef BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP #ifndef BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP
#define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP #define BOOST_FUSION_ADAPTED_STRUCT_DETAIL_DEFINE_STRUCT_INLINE_HPP
#include <boost/config.hpp>
#include <boost/fusion/support/category_of.hpp> #include <boost/fusion/support/category_of.hpp>
#include <boost/fusion/sequence/sequence_facade.hpp> #include <boost/fusion/sequence/sequence_facade.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp> #include <boost/fusion/iterator/iterator_facade.hpp>
@ -25,8 +26,32 @@
#include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/seq/for_each_i.hpp>
#include <boost/preprocessor/seq/size.hpp> #include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/enum.hpp> #include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/seq/seq.hpp>
#include <boost/preprocessor/tuple/elem.hpp> #include <boost/preprocessor/tuple/elem.hpp>
// MSVC and GCC <= 4.4 have a bug that affects partial specializations of
// nested templates under some circumstances. This affects the implementation
// of BOOST_FUSION_DEFINE_STRUCT_INLINE, which uses such specializations for
// the iterator class's 'deref' and 'value_of' metafunctions. On these compilers
// an alternate implementation for these metafunctions is used that does not
// require such specializations. The alternate implementation takes longer
// to compile so its use is restricted to the offending compilers.
// For MSVC, the bug was was reported at https://connect.microsoft.com/VisualStudio/feedback/details/757891/c-compiler-error-involving-partial-specializations-of-nested-templates
// For GCC, 4.4 and earlier are no longer maintained so there is no need
// to report a bug.
#if defined(BOOST_MSVC) || (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ <= 4)))
#define BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND
#endif
#ifdef BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND
#include <boost/type_traits/add_const.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/mpl/if.hpp>
#include <boost/fusion/sequence/intrinsic/at_c.hpp>
#include <boost/fusion/container/vector.hpp>
#endif
#define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY(R, DATA, N, ATTRIBUTE) \ #define BOOST_FUSION_MAKE_DEFAULT_INIT_LIST_ENTRY(R, DATA, N, ATTRIBUTE) \
BOOST_PP_COMMA_IF(N) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)() BOOST_PP_COMMA_IF(N) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)()
@ -148,6 +173,95 @@
#define BOOST_FUSION_MAKE_DATA_MEMBER(R, DATA, N, ATTRIBUTE) \ #define BOOST_FUSION_MAKE_DATA_MEMBER(R, DATA, N, ATTRIBUTE) \
BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE); BOOST_PP_TUPLE_ELEM(2, 0, ATTRIBUTE) BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE);
#ifdef BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND
#define BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTE_SEQ_SIZE) \
template <typename boost_fusion_detail_Iterator> \
struct value_of : boost::fusion::result_of::at_c< \
ref_vec_t, \
boost_fusion_detail_Iterator::index::value \
> \
{ \
};
#define BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \
template <typename boost_fusion_detail_Iterator> \
struct deref \
{ \
typedef typename boost::remove_const< \
boost_fusion_detail_Iterator \
>::type iterator_raw_type; \
\
static const int index = iterator_raw_type::index::value; \
\
typedef typename boost::fusion::result_of::at_c< \
ref_vec_t, \
index \
>::type result_raw_type; \
\
typedef typename boost::mpl::if_< \
boost::is_const<typename iterator_raw_type::sequence_type>, \
typename boost::add_const<result_raw_type>::type, \
result_raw_type \
>::type type; \
\
static type call(iterator_raw_type const& iter) \
{ \
return boost::fusion::at_c<index>(iter.ref_vec); \
} \
};
#define BOOST_FUSION_MAKE_ITERATOR_WKND_FIELD_NAME(R, DATA, N, ATTRIBUTE) \
BOOST_PP_COMMA_IF(N) seq.BOOST_PP_TUPLE_ELEM(2, 1, ATTRIBUTE)
#define BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES(ATTRIBUTES_SEQ) \
, ref_vec(BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_FUSION_MAKE_ITERATOR_WKND_FIELD_NAME, \
~, \
BOOST_PP_SEQ_TAIL(ATTRIBUTES_SEQ)))
#define BOOST_FUSION_MAKE_ITERATOR_WKND_REF(Z, N, DATA) \
BOOST_PP_COMMA_IF(N) \
typename boost::mpl::if_< \
boost::is_const<boost_fusion_detail_Seq>, \
typename boost::add_const< \
typename boost_fusion_detail_Seq::t##N##_type \
>::type, \
typename boost_fusion_detail_Seq::t##N##_type \
>::type&
#define BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE) \
typedef boost::fusion::vector< \
BOOST_PP_REPEAT( \
ATTRIBUTES_SEQ_SIZE, \
BOOST_FUSION_MAKE_ITERATOR_WKND_REF, \
~) \
> ref_vec_t; \
\
ref_vec_t ref_vec;
#else
#define BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTES_SEQ_SIZE) \
template <typename boost_fusion_detail_T> struct value_of; \
BOOST_PP_REPEAT( \
ATTRIBUTES_SEQ_SIZE, \
BOOST_FUSION_MAKE_ITERATOR_VALUE_OF_SPECS, \
NAME)
#define BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \
template <typename boost_fusion_detail_T> struct deref; \
BOOST_PP_SEQ_FOR_EACH_I( \
BOOST_FUSION_MAKE_ITERATOR_DEREF_SPECS, \
NAME, \
ATTRIBUTES_SEQ)
#define BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES(ATTRIBUTES_SEQ)
#define BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE)
#endif // BOOST_FUSION_NEED_NESTED_TEMPLATE_PARTIAL_SPEC_WKND
// Note: We can't nest the iterator inside the struct because we run into // Note: We can't nest the iterator inside the struct because we run into
// a MSVC10 bug involving partial specializations of nested templates. // a MSVC10 bug involving partial specializations of nested templates.
@ -219,21 +333,18 @@
typedef boost_fusion_detail_Seq sequence_type; \ typedef boost_fusion_detail_Seq sequence_type; \
\ \
BOOST_FUSION_ITERATOR_NAME(NAME)(boost_fusion_detail_Seq& seq) \ BOOST_FUSION_ITERATOR_NAME(NAME)(boost_fusion_detail_Seq& seq) \
: seq_(seq) {} \ : seq_(seq) \
BOOST_FUSION_DEFINE_ITERATOR_WKND_INIT_LIST_ENTRIES( \
(0)ATTRIBUTES_SEQ) \
{} \
\ \
boost_fusion_detail_Seq& seq_; \ boost_fusion_detail_Seq& seq_; \
\ \
template <typename boost_fusion_detail_T> struct value_of; \ BOOST_FUSION_DEFINE_ITERATOR_WKND_MEMBERS(ATTRIBUTES_SEQ_SIZE) \
BOOST_PP_REPEAT( \
ATTRIBUTES_SEQ_SIZE, \
BOOST_FUSION_MAKE_ITERATOR_VALUE_OF_SPECS, \
NAME) \
\ \
template <typename boost_fusion_detail_T> struct deref; \ BOOST_FUSION_DEFINE_ITERATOR_VALUE_OF(NAME, ATTRIBUTES_SEQ_SIZE) \
BOOST_PP_SEQ_FOR_EACH_I( \ \
BOOST_FUSION_MAKE_ITERATOR_DEREF_SPECS, \ BOOST_FUSION_DEFINE_ITERATOR_DEREF(NAME, ATTRIBUTES_SEQ) \
NAME, \
ATTRIBUTES_SEQ) \
\ \
template <typename boost_fusion_detail_It> \ template <typename boost_fusion_detail_It> \
struct next \ struct next \

View File

@ -26,6 +26,16 @@ struct cls
) )
}; };
template <typename = int>
struct tpl_cls
{
BOOST_FUSION_DEFINE_STRUCT_INLINE(
point,
(int, x)
(int, y)
)
};
namespace ns namespace ns
{ {
BOOST_FUSION_DEFINE_STRUCT_INLINE(s, (int, m)) BOOST_FUSION_DEFINE_STRUCT_INLINE(s, (int, m))
@ -33,8 +43,8 @@ namespace ns
BOOST_FUSION_DEFINE_STRUCT_INLINE(empty_struct, ) BOOST_FUSION_DEFINE_STRUCT_INLINE(empty_struct, )
} }
int template <typename Point>
main() void run_test()
{ {
using namespace boost::fusion; using namespace boost::fusion;
@ -48,8 +58,8 @@ main()
} }
{ {
BOOST_MPL_ASSERT_NOT((traits::is_view<cls::point>)); BOOST_MPL_ASSERT_NOT((traits::is_view<Point>));
cls::point p(123, 456); Point p(123, 456);
std::cout << at_c<0>(p) << std::endl; std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl; std::cout << at_c<1>(p) << std::endl;
@ -60,8 +70,8 @@ main()
at_c<1>(p) = 9; at_c<1>(p) = 9;
BOOST_TEST(p == make_vector(6, 9)); BOOST_TEST(p == make_vector(6, 9));
BOOST_STATIC_ASSERT(boost::fusion::result_of::size<cls::point>::value == 2); BOOST_STATIC_ASSERT(boost::fusion::result_of::size<Point>::value == 2);
BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<cls::point>::value); BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<Point>::value);
BOOST_TEST(front(p) == 6); BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9); BOOST_TEST(back(p) == 9);
@ -69,7 +79,7 @@ main()
{ {
vector<int, float> v1(4, 2); vector<int, float> v1(4, 2);
cls::point v2(5, 3); Point v2(5, 3);
vector<long, double> v3(5, 4); vector<long, double> v3(5, 4);
BOOST_TEST(v1 < v2); BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2); BOOST_TEST(v1 <= v2);
@ -82,15 +92,15 @@ main()
} }
{ {
// conversion from cls::point to vector // conversion from Point to vector
cls::point p(5, 3); Point p(5, 3);
vector<int, long> v(p); vector<int, long> v(p);
v = p; v = p;
} }
{ {
// conversion from cls::point to list // conversion from Point to list
cls::point p(5, 3); Point p(5, 3);
list<int, long> l(p); list<int, long> l(p);
l = p; l = p;
} }
@ -105,13 +115,20 @@ main()
} }
{ {
cls::point p = make_list(5,3); Point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3)); BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5); p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5)); BOOST_TEST(p == make_vector(3,5));
} }
}
return boost::report_errors();
int
main()
{
run_test<cls::point>(); // test with non-template enclosing class
run_test<tpl_cls<>::point>(); // test with template enclosing class
return boost::report_errors();
} }

View File

@ -27,6 +27,17 @@ struct cls
) )
}; };
template <typename = int>
struct tpl_cls
{
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE(
(X)(Y),
point,
(X, x)
(Y, y)
)
};
namespace ns namespace ns
{ {
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), s, (M, m)) BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), s, (M, m))
@ -34,13 +45,11 @@ namespace ns
BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), empty_struct, ) BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE((M), empty_struct, )
} }
int template <typename Point>
main() void run_test()
{ {
using namespace boost::fusion; using namespace boost::fusion;
typedef cls::point<int, int> point;
std::cout << tuple_open('['); std::cout << tuple_open('[');
std::cout << tuple_close(']'); std::cout << tuple_close(']');
std::cout << tuple_delimiter(", "); std::cout << tuple_delimiter(", ");
@ -51,8 +60,8 @@ main()
} }
{ {
BOOST_MPL_ASSERT_NOT((traits::is_view<point>)); BOOST_MPL_ASSERT_NOT((traits::is_view<Point>));
point p(123, 456); Point p(123, 456);
std::cout << at_c<0>(p) << std::endl; std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl; std::cout << at_c<1>(p) << std::endl;
@ -63,8 +72,8 @@ main()
at_c<1>(p) = 9; at_c<1>(p) = 9;
BOOST_TEST(p == make_vector(6, 9)); BOOST_TEST(p == make_vector(6, 9));
BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 2); BOOST_STATIC_ASSERT(boost::fusion::result_of::size<Point>::value == 2);
BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value); BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<Point>::value);
BOOST_TEST(front(p) == 6); BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9); BOOST_TEST(back(p) == 9);
@ -72,7 +81,7 @@ main()
{ {
vector<int, float> v1(4, 2); vector<int, float> v1(4, 2);
point v2(5, 3); Point v2(5, 3);
vector<long, double> v3(5, 4); vector<long, double> v3(5, 4);
BOOST_TEST(v1 < v2); BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2); BOOST_TEST(v1 <= v2);
@ -85,15 +94,15 @@ main()
} }
{ {
// conversion from point to vector // conversion from Point to vector
point p(5, 3); Point p(5, 3);
vector<int, long> v(p); vector<int, long> v(p);
v = p; v = p;
} }
{ {
// conversion from point to list // conversion from Point to list
point p(5, 3); Point p(5, 3);
list<int, long> l(p); list<int, long> l(p);
l = p; l = p;
} }
@ -109,12 +118,19 @@ main()
{ {
point p = make_list(5,3); Point p = make_list(5,3);
BOOST_TEST(p == make_vector(5,3)); BOOST_TEST(p == make_vector(5,3));
p = make_list(3,5); p = make_list(3,5);
BOOST_TEST(p == make_vector(3,5)); BOOST_TEST(p == make_vector(3,5));
} }
}
int
main()
{
run_test<cls::point<int, int> >(); // test non-template enclosing class
run_test<tpl_cls<>::point<int, int> >(); // test template enclosing class
return boost::report_errors(); return boost::report_errors();
} }