Opened 7 years ago
#11248 new Bugs
Some algorithms with requirement for SinglePassRange accept range only by const reference
Reported by: | Owned by: | Neil Groves | |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost 1.57.0 | Severity: | Problem |
Keywords: | Cc: |
Description
I came up with it when tried to use generator made by boost.coroutine with boost range algorithms. The following code doesn't compile with MSVC 2012
#include <boost/range/distance.hpp> #include <boost/coroutine/all.hpp> using namespace boost::range; using namespace boost::coroutines; asymmetric_coroutine<int>::pull_type make_dummy_range() { return asymmetric_coroutine<int>::pull_type([](asymmetric_coroutine<int>::push_type& yield) { yield(1); }); } int _tmain(int argc, _TCHAR* argv[]) { boost::distance(make_dummy_range()); // error return 0; }
with error
D:\Work\3rdparty\boost_1_58_0\boost/concept_check.hpp(181): error C2079: 'boost::CopyConstructible<TT>::b' uses undefined struct 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> TT=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> and 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(124) : see reference to class template instantiation 'boost::CopyConstructible<TT>' being compiled 1> with 1> [ 1> TT=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(147) : see reference to class template instantiation 'boost::range_detail::IncrementableIteratorConcept<Iterator>' being compiled 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/concept/detail/msvc.hpp(29) : see reference to class template instantiation 'boost::range_detail::SinglePassIteratorConcept<Iterator>' being compiled 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/concept/detail/msvc.hpp(28) : while compiling class template member function 'void boost::concepts::check<Model>::failed(Model *)' 1> with 1> [ 1> Model=boost::range_detail::SinglePassIteratorConcept<boost::coroutines::pull_coroutine<int>::const_iterator> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/concept/detail/msvc.hpp(66) : see reference to class template instantiation 'boost::concepts::check<Model>' being compiled 1> with 1> [ 1> Model=boost::range_detail::SinglePassIteratorConcept<boost::coroutines::pull_coroutine<int>::const_iterator> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(279) : see reference to class template instantiation 'boost::concepts::require<Model>' being compiled 1> with 1> [ 1> Model=boost::range_detail::SinglePassIteratorConcept<boost::coroutines::pull_coroutine<int>::const_iterator> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/concept/detail/has_constraints.hpp(42) : see reference to class template instantiation 'boost::SinglePassRangeConcept<T>' being compiled 1> with 1> [ 1> T=boost::coroutines::pull_coroutine<int> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/concept/detail/msvc.hpp(58) : see reference to class template instantiation 'boost::concepts::not_satisfied<Model>' being compiled 1> with 1> [ 1> Model=boost::SinglePassRangeConcept<boost::coroutines::pull_coroutine<int>> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/algorithm/for_each.hpp(72) : see reference to class template instantiation 'boost::concepts::require<Model>' being compiled 1> with 1> [ 1> Model=boost::SinglePassRangeConcept<boost::coroutines::pull_coroutine<int>> 1> ] 1> coroutine_bug.cpp(29) : see reference to function template instantiation 'UnaryFunction boost::range::for_each<boost::coroutines::pull_coroutine<R>,wmain::<lambda_d9c6ee6ee85186807f477d3ab241bdd7>>(SinglePassRange &,UnaryFunction)' being compiled 1> with 1> [ 1> UnaryFunction=wmain::<lambda_d9c6ee6ee85186807f477d3ab241bdd7>, 1> R=int, 1> SinglePassRange=boost::coroutines::pull_coroutine<int> 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/coroutine/asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/iterator/iterator_categories.hpp(119) : see reference to class template instantiation 'std::iterator_traits<_Iter>' being compiled 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(126) : see reference to class template instantiation 'boost::iterators::iterator_traversal<Iterator>' being compiled 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364): error C2146: syntax error : missing ';' before identifier 'iterator_category' 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364): error C2602: 'std::iterator_traits<_Iter>::iterator_category' is not a member of a base class of 'std::iterator_traits<_Iter>' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364) : see declaration of 'std::iterator_traits<_Iter>::iterator_category' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(364): error C2868: 'std::iterator_traits<_Iter>::iterator_category' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/coroutine/asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365): error C2146: syntax error : missing ';' before identifier 'value_type' 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365): error C2602: 'std::iterator_traits<_Iter>::value_type' is not a member of a base class of 'std::iterator_traits<_Iter>' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365) : see declaration of 'std::iterator_traits<_Iter>::value_type' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(365): error C2868: 'std::iterator_traits<_Iter>::value_type' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/coroutine/asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366): error C2146: syntax error : missing ';' before identifier 'difference_type' 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366): error C2602: 'std::iterator_traits<_Iter>::difference_type' is not a member of a base class of 'std::iterator_traits<_Iter>' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366) : see declaration of 'std::iterator_traits<_Iter>::difference_type' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(366): error C2868: 'std::iterator_traits<_Iter>::difference_type' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/coroutine/asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368): error C2146: syntax error : missing ';' before identifier 'pointer' 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368): error C2602: 'std::iterator_traits<_Iter>::pointer' is not a member of a base class of 'std::iterator_traits<_Iter>' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368) : see declaration of 'std::iterator_traits<_Iter>::pointer' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(368): error C2868: 'std::iterator_traits<_Iter>::pointer' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369): error C2027: use of undefined type 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/coroutine/asymmetric_coroutine.hpp(812) : see declaration of 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> R=int 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369): error C2146: syntax error : missing ';' before identifier 'reference' 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369): error C2602: 'std::iterator_traits<_Iter>::reference' is not a member of a base class of 'std::iterator_traits<_Iter>' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369) : see declaration of 'std::iterator_traits<_Iter>::reference' 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xutility(369): error C2868: 'std::iterator_traits<_Iter>::reference' : illegal syntax for using-declaration; expected qualified-name 1> with 1> [ 1> _Iter=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41): error C2516: 'boost::mpl::if_<T1,T2,T3>::type' : is not a legal base class 1> with 1> [ 1> T1=boost::is_convertible<int,std::output_iterator_tag>, 1> T2=boost::mpl::identity<boost::iterators::incrementable_traversal_tag>, 1> T3=void 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/if.hpp(70) : see declaration of 'boost::mpl::if_<T1,T2,T3>::type' 1> with 1> [ 1> T1=boost::is_convertible<int,std::output_iterator_tag>, 1> T2=boost::mpl::identity<boost::iterators::incrementable_traversal_tag>, 1> T3=void 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,std::output_iterator_tag>, 1> F1=boost::mpl::identity<boost::iterators::incrementable_traversal_tag>, 1> F2=void 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,std::input_iterator_tag>, 1> F1=boost::mpl::identity<boost::iterators::single_pass_traversal_tag>, 1> F2=boost::mpl::eval_if<boost::is_convertible<int,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,std::forward_iterator_tag>, 1> F1=boost::mpl::identity<boost::iterators::forward_traversal_tag>, 1> F2=boost::mpl::eval_if<boost::is_convertible<int,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,std::bidirectional_iterator_tag>, 1> F1=boost::mpl::identity<boost::iterators::bidirectional_traversal_tag>, 1> F2=boost::mpl::eval_if<boost::is_convertible<int,std::forward_iterator_tag>,boost::mpl::identity<boost::iterators::forward_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/iterator/iterator_categories.hpp(99) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,std::random_access_iterator_tag>, 1> F1=boost::mpl::identity<boost::iterators::random_access_traversal_tag>, 1> F2=boost::mpl::eval_if<boost::is_convertible<int,std::bidirectional_iterator_tag>,boost::mpl::identity<boost::iterators::bidirectional_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::forward_iterator_tag>,boost::mpl::identity<boost::iterators::forward_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::input_iterator_tag>,boost::mpl::identity<boost::iterators::single_pass_traversal_tag>,boost::mpl::eval_if<boost::is_convertible<int,std::output_iterator_tag>,boost::mpl::identity<boost::iterators::incrementable_traversal_tag>,void>>>> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/mpl/eval_if.hpp(41) : see reference to class template instantiation 'boost::iterators::detail::old_category_to_traversal<Cat>' being compiled 1> with 1> [ 1> Cat=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/iterator/iterator_categories.hpp(113) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled 1> with 1> [ 1> C=boost::is_convertible<int,boost::iterators::incrementable_traversal_tag>, 1> F1=boost::mpl::identity<int>, 1> F2=boost::iterators::detail::old_category_to_traversal<int> 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/iterator/iterator_categories.hpp(121) : see reference to class template instantiation 'boost::iterators::iterator_category_to_traversal<Cat>' being compiled 1> with 1> [ 1> Cat=int 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(126): error C2039: 'type' : is not a member of 'boost::iterators::iterator_traversal<Iterator>' 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(126): error C2146: syntax error : missing ';' before identifier 'traversal_category' 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(126): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(128): error C2065: 'traversal_category' : undeclared identifier 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(128): error C2923: 'boost::Convertible' : 'traversal_category' is not a valid template type argument for parameter 'X' 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(128): error C2893: Failed to specialize function template 'boost::concepts::require<Model> boost::concepts::require_(void (__cdecl *)(Model))' 1> With the following template arguments: 1> 'boost::Convertible' 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(128): error C2056: illegal expression 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(140): error C2079: 'boost::range_detail::IncrementableIteratorConcept<Iterator>::i' uses undefined struct 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> and 1> [ 1> R=int 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/concept_check.hpp(239): error C2079: 'boost::EqualityComparable<TT>::a' uses undefined struct 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> TT=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> and 1> [ 1> R=int 1> ] 1> D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(148) : see reference to class template instantiation 'boost::EqualityComparable<TT>' being compiled 1> with 1> [ 1> TT=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/concept_check.hpp(239): error C2079: 'boost::EqualityComparable<TT>::b' uses undefined struct 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> TT=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> and 1> [ 1> R=int 1> ] 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(150): error C2146: syntax error : missing ',' before identifier 'traversal_category' 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(150): error C2065: 'traversal_category' : undeclared identifier 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(150): error C2893: Failed to specialize function template 'boost::concepts::require<Model> boost::concepts::require_(void (__cdecl *)(Model))' 1> With the following template arguments: 1> 'boost::Convertible' 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(150): error C2056: illegal expression 1>D:\Work\3rdparty\boost_1_58_0\boost/range/concepts.hpp(174): error C2079: 'boost::range_detail::SinglePassIteratorConcept<Iterator>::i' uses undefined struct 'boost::coroutines::pull_coroutine<R>::const_iterator' 1> with 1> [ 1> Iterator=boost::coroutines::pull_coroutine<int>::const_iterator 1> ] 1> and 1> [ 1> R=int 1> ] 1> 1>Build FAILED. 1>
Generator models SinglePassRange and modify itself will iterating, but distance accept range only by const reference
template< class T > inline BOOST_DEDUCED_TYPENAME range_difference<T>::type distance( const T& r ) { return std::distance( boost::begin( r ), boost::end( r ) ); }
I checked other algorithms and found that some of them have non const reference overload (for example count)
template<class SinglePassRange, class Value> typename range_difference<SinglePassRange>::type count(SinglePassRange& rng, const Value& val); template<class SinglePassRange, class Value> typename range_difference<const SinglePassRange>::type count(const SinglePassRange& rng, const Value& val);
I tried count instead of distance and I was suprised that it doesn't compile too.
asymmetric_coroutine<int>::pull_type make_dummy_range() { return asymmetric_coroutine<int>::pull_type([](asymmetric_coroutine<int>::push_type& yield) { yield(1); }); } int _tmain(int argc, _TCHAR* argv[]) { asymmetric_coroutine<int>::pull_type r = make_dummy_range(); boost::count(r, 1); //still complains on const_iterator return 0; }
I don't understand why MSVC12 compiler still prefer const ref overload
template<class SinglePassRange, class Value> typename range_difference<const SinglePassRange>::type count(const SinglePassRange& rng, const Value& val);
but it is
Note:
See TracTickets
for help on using tickets.