Boost logo

Boost :

Subject: Re: [boost] [fusion] for_each on gcc 4.7
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-06-21 05:54:26


On 06/21/12 01:33, Joel de Guzman wrote:
> On 6/21/2012 10:00 AM, Daniel Larimer wrote:
>>
>> On Jun 20, 2012, at 9:57 PM, Daniel Larimer wrote:
>>
>>> On Jun 20, 2012, at 7:36 PM, Joel de Guzman wrote:
>>>
>>>> On 6/20/2012 1:37 PM, Daniel Larimer wrote:
>>>>> I recently attempted to update to gcc 4.7 and code that compiled
>>>>> with 4.5.3 broke.
>>>>>
>>>>> It appears that boost::fusion expects
>>>>> boost::fusion::random_access_traversal_tag to implicitly cast to
>>>>> mpl::bool_<false>.
>>>>>
>>>>> Switching the 3rd argument from mpl::bool_<false> to an extra
>>>>> template arg (that was ignored), seems to fix the compilation errors.
>>>>>
>>>>> Compiled with std=c++11
>>>>
>>>> Do you have a minimal test case?
>>>
>>> #include<boost/fusion/container/vector.hpp>
>>> #include<boost/fusion/algorithm.hpp>
>>> #include<boost/fusion/include/make_vector.hpp>
>>>
>>> struct visitor {
>>> template<typename T>
>>> void operator()( T t )const{}
>>> };
>>>
>>> int main() {
>>> visitor v;
>>> boost::fusion::for_each( boost::fusion::make_vector(5,6.6), v );
>>> return 0;
>>> }
>>>
>> I could get things to compile by editing
>> boost/fusion/algorithm/iteration/detail/for_each.hpp and changing the
>> last parameter to Ty. It appears that parameter was ignored anyway
>> and that we didn't care about the type.
>>
>> template<typename Sequence, typename F, typename Ty>
>> inline void
>> for_each(Sequence& seq, F const& f, Ty) // unsegmented
>> implementation
>> {
>> detail::for_each_dispatch(seq, f, typename
>> traits::category_of<Sequence>::type());
>> }
>
> No, that is not a proper fix. It just bypasses the problem, which seems
> to be
> a gcc 4.7 problem. There is nothing wrong with Fusion code AFAICT. Fusion
> does not expect boost::fusion::random_access_traversal_tag to be converted
> to an mpl::bool_<false>. That function (detail::for_each) is called this
> way:
>
> detail::for_each(seq, f, typename
> traits::is_segmented<Sequence>::type());
>
> And there is nothing wrong with that code AFAICT.
>
> Sorry, I do not have gcc 4.7 ATM, but at any rate, what errors do you get
> with the code above. Both VC10 and gcc-4.6 compiles it just fine.
The code compiles & runs OK with 4.7 as it was on 20120204 on ubuntu:

make -Wfor_each_rand_access_tag.cpp run
install -d `dirname for_each_rand_access_tag.o`
/home/evansl/download/gcc/4.7-20120204/install/bin/g++ -c -Wall
-Wstrict-overflow -ftemplate-depth-300 -O0 -std=gnu++11
-I/home/evansl/prog_dev/boost-svn/ro/boost_1_49_0 -DTEMPLATE_DEPTH=300
 for_each_rand_access_tag.cpp -MMD -o for_each_rand_access_tag.o
sed -e 's#^for_each_rand_access_tag.o:#for_each_rand_access_tag.o:#'
./for_each_rand_access_tag.d> ./for_each_rand_access_tag.o.dep
#rm ./for_each_rand_access_tag.d
/home/evansl/download/gcc/4.7-20120204/install/bin/g++
-L/home/evansl/download/gcc/4.7-20120204/install/lib64 -Wl,-rpath
-Wl,/home/evansl/download/gcc/4.7-20120204/install/lib64 -llapack -lblas
-lgfortran ./for_each_rand_access_tag.o -o for_each_rand_access_tag.exe
./for_each_rand_access_tag.exe

Compilation finished at Thu Jun 21 04:51:54


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk