Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] Compile Error using BOOST_FUSION_DEFINE_STRUCT_INLINE with VC10 and GCC 4.2.1
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2012-10-23 22:45:14


> the following code gives a compile error on VC10 and GCC 4.2.1. Clang
> and GCC 4.7 like it:
>
> #include <boost/fusion/sequence.hpp>
> #include <boost/fusion/include/define_struct_inline.hpp>
> #include <iostream>
>
> template<class T>
> struct enclosing
> {
> BOOST_FUSION_DEFINE_STRUCT_INLINE(
> employee,
> (std::string, name)
> (int, age))
> };
>
>
> int main()
> {
> enclosing<int>::employee e;
> e.name="abc";
> std::cout<<boost::fusion::deref(boost::fusion::begin(e));
> }
>
> [snip]
>
> I don't have a clue what is wrong here. Is the error on my side? i just
> added the template<class T> to the example code of
> BOOST_FUSION_DEFINE_STRUCT_INLINE.
> Without, everything is fine.

For MSVC, this is caused by a bug that seems to be triggered when a triply
nested template class (i.e. a nested template class inside a nested
template class inside a template class) is partially specialized. I reported
the bug to Microsoft [1], but haven't heard back from them.

This actually used to be a problem for BOOST_FUSION_DEFINE_TPL_STRUCT_INLINE
even with a non-template enclosing class, because in my original design,
the iterator class was nested inside the sequence class, so you had a triply
nested template class (the iterator metafunction nested inside the iterator
nested inside the sequnce). I worked around that by declaring the iterator
in the same scope as the sequence, so one level of nesting was removed,
but if you use a template enclosing class, you once again have a triply
nested template (the iterator metafunction nested inside the iterator nested
inside the enclosing class), and I don't see what I can do about *that*.

GCC 4.2 seems to be suffering from a similar bug. Your example code works
with GCC 4.5 and higher, and fails to compile with GCC 4.4 and lower. There's
not much to do in terms of reporting this bug, since 4.4 and earlier are no
longer maintained.

If anyone can suggest a workaround for these compiler bugs, I am happy to
implement them.

Regards,
Nate

[1] https://connect.microsoft.com/VisualStudio/feedback/details/757891/c-compiler-error-involving-partial-specializations-of-nested-templates
                                               


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net