cling icon indicating copy to clipboard operation
cling copied to clipboard

Meet a bug when encountering errors

Open hellocodeM opened this issue 9 years ago • 3 comments

Hey, I found something unexpected when I write some wrong codes, like this:

typedef mpl::range_c<int, 0, 10> ran;
typedef mpl::plus<_1, mpl::int_<2> > add2;
/* this line will get some errors when template instantiation */
typedef mpl::transform<ran, add2>::type newran;  
/* but when I type in the same line, there will be no errors. */
typedef mpl::transform<ran, add2>::type newran;  

Besides, after the second line, the type "newran" will becomes int.

Maybe you should do something to fix this. Thank you!

hellocodeM avatar Jun 11 '15 07:06 hellocodeM

Thanks for the report! Could you make the reproducer self-containing, please?

vgvassilev avatar Jun 11 '15 07:06 vgvassilev

Okay, but the code is a little prolix, as you know..

Before it, I should do some explaining. Since I'm learn template metaprogramming(TMP), I'm used to make some test with cling, it's quite useful to do this job.

In TMP, range_c is not an extendsible sequence, so you could not transform it. As a result, the code "tyepdef mpl::transform<ran, add2>::type ran2" should encounter a template instantiation error, but when you type in it again, the error won't happen and the ran2 becomes int, as I have described.

If anything I can help you, just contact me.

chapter5 ➜ cling
[cling]$ #include "common-header.hpp"
[cling]$ typedef mpl::range_c<int, 0, 10> ran;
[cling]$ typedef mpl::plus<_1, mpl::int_<2> > add2;
[cling]$ typedef mpl::transform<ran, add2>::type ran2;
In file included from input_line_4:1:
In file included from /home/ming/work/C++/tmp/chapter5/common-header.hpp:38:
In file included from /usr/include/boost/mpl/copy.hpp:20:
In file included from /usr/include/boost/mpl/aux_/inserter_algorithm.hpp:24:
/usr/include/boost/mpl/clear.hpp:29:7: error: implicit instantiation of undefined template
      'boost::mpl::clear_impl<boost::mpl::aux::half_open_range_tag>::apply<boost::mpl::range_c<int, 0, 10> >'
    : clear_impl< typename sequence_tag<Sequence>::type >
      ^
/usr/include/boost/mpl/transform.hpp:113:1: note: in instantiation of template class 'boost::mpl::clear<boost::mpl::range_c<int, 0, 10> >' requested
      here
BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, transform1)                    
^
/usr/include/boost/mpl/aux_/inserter_algorithm.hpp:52:36: note: expanded from macro 'BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF'
    : if_< has_push_back< typename clear<P1>::type> \
                                   ^
/usr/include/boost/mpl/eval_if.hpp:38:22: note: in instantiation of template class 'boost::mpl::transform1<boost::mpl::range_c<int, 0, 10>,
      boost::mpl::plus<mpl_::arg<1>, mpl_::int_<2>, mpl_::na, mpl_::na, mpl_::na>, mpl_::na>' requested here
    typedef typename f_::type type;
                     ^
/usr/include/boost/mpl/transform.hpp:138:1: note: in instantiation of template class 'boost::mpl::eval_if<boost::mpl::or_<boost::mpl::is_na<mpl_::na>,
      boost::mpl::is_lambda_expression<boost::mpl::plus<mpl_::arg<1>, mpl_::int_<2>, mpl_::na, mpl_::na, mpl_::na> >,
      boost::mpl::not_<boost::mpl::is_sequence<boost::mpl::plus<mpl_::arg<1>, mpl_::int_<2>, mpl_::na, mpl_::na, mpl_::na> > >, mpl_::bool_<false>,
      mpl_::bool_<false> >, boost::mpl::transform1<boost::mpl::range_c<int, 0, 10>, boost::mpl::plus<mpl_::arg<1>, mpl_::int_<2>, mpl_::na, mpl_::na,
      mpl_::na>, mpl_::na>, boost::mpl::transform2<boost::mpl::range_c<int, 0, 10>, boost::mpl::plus<mpl_::arg<1>, mpl_::int_<2>, mpl_::na, mpl_::na,
      mpl_::na>, mpl_::na, mpl_::na> >' requested here
AUX778076_TRANSFORM_DEF(transform)
^
/usr/include/boost/mpl/transform.hpp:125:22: note: expanded from macro 'AUX778076_TRANSFORM_DEF'
    typedef typename eval_if<                                           \
                     ^
input_line_7:2:15: note: in instantiation of template class 'boost::mpl::transform<boost::mpl::range_c<int, 0, 10>, boost::mpl::plus<mpl_::arg<1>,
      mpl_::int_<2>, mpl_::na, mpl_::na, mpl_::na>, mpl_::na, mpl_::na>' requested here
 typedef mpl::transform<ran, add2>::type ran2;
              ^
/usr/include/boost/mpl/aux_/clear_impl.hpp:28:42: note: template is declared here
    template< typename Sequence > struct apply;
                                         ^
[cling]$ typedef mpl::transform<ran, add2>::type ran2;
[cling]$ typeid(ran2).name()
(const char *) "i"

hellocodeM avatar Jun 11 '15 10:06 hellocodeM

Is this still an issue? Can I close this?

vgvassilev avatar Jan 20 '17 10:01 vgvassilev