Opened 6 years ago

Last modified 5 years ago

#12732 new Bugs

Karma problem converting a char vector to string

Reported by: Braden McDaniel <braden@…> Owned by: Joel de Guzman
Milestone: To Be Determined Component: fusion
Version: Boost 1.64.0 Severity: Regression
Keywords: Cc:

Description

The version of Boost.Spirit.Karma included with Boost 1.63.0 appears to have a problem converting a char vector to a string when building with Apple Clang 8.0 using the -std=c++14 (or -std=gnu++14) option. Consider the following example:

#include <boost/spirit/include/karma.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

struct foo { 
  std::string a, b; 
}; 

BOOST_FUSION_ADAPT_STRUCT( 
  foo, 
  (std::string, a) 
  (std::string, b) 
) 

int main() 
{ 
  using namespace boost::spirit::karma; 

  typedef rule<std::back_insert_iterator<std::string>, foo(), space_type> 
    rule_t; 

  rule_t r 
    =   +char_ << '(' << string << ')' 
    |   skip[string] << string 
    ; 

  foo f = {"a", "b"}; 
  std::string s; 
  generate_delimited(std::back_inserter(s), r, space, f); 
} 

When compiled with the -std=c++14 and -stdlib=libc++ options, the following errors are emitted:

$ c++ -I ~/Build/ng-core-Debug/API/inc -std=c++14 -stdlib=libc++ -o karma-char-seq karma-char-seq.cpp
In file included from karma-char-seq.cpp:1:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/phoenix.hpp:11:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/phoenix/phoenix.hpp:11:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/phoenix/core.hpp:13:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/phoenix/core/debug.hpp:17:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/proto/proto.hpp:12:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/proto/core.hpp:21:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/proto/fusion.hpp:22:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/include/intrinsic.hpp:11:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/sequence/intrinsic.hpp:23:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/sequence/intrinsic/swap.hpp:15:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/view/zip_view.hpp:12:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/view/zip_view/zip_view.hpp:16:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/view/zip_view/detail/begin_impl.hpp:14:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/algorithm/transformation/transform.hpp:11:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/view/transform_view/transform_view.hpp:22:
In file included from /Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/container/vector/vector10.hpp:25:
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/container/vector/vector.hpp:168:19: error: 
      no matching constructor for initialization of 'std::__1::vector<char,
      std::__1::allocator<char> >'
                : elem(std::forward<U>(rhs))
                  ^    ~~~~~~~~~~~~~~~~~~~~
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/container/vector/vector.hpp:208:19: note: 
      in instantiation of function template specialization
      'boost::fusion::vector_detail::store<0, std::__1::vector<char,
      std::__1::allocator<char> > >::store<std::__1::basic_string<char> &,
      void>' requested here
                : store<I, T>(forward_at_c<I>(std::forward<Sequence>(rhs)))...
                  ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/fusion/container/vector/vector.hpp:319:15: note: 
      in instantiation of function template specialization
      'boost::fusion::vector_detail::vector_data<boost::fusion::detail::index_sequence<0,
      1>, std::__1::vector<char, std::__1::allocator<char> >,
      std::__1::basic_string<char> >::vector_data<foo, foo, void>' requested
      here
            : base(vector_detail::each_elem(), std::forward<Sequence>(seq))
              ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/type_traits/is_convertible.hpp:482:56: note: 
      in instantiation of function template specialization
      'boost::fusion::vector<std::__1::vector<char, std::__1::allocator<char> >,
      std::__1::basic_string<char> >::vector<foo, foo, void>' requested here
struct is_convertible : public integral_constant<bool, BOOST_IS_CONVERTI...
                                                       ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/type_traits/intrinsics.hpp:214:63: note: 
      expanded from macro 'BOOST_IS_CONVERTIBLE'
#     define BOOST_IS_CONVERTIBLE(T,U) __is_convertible_to(T,U)
                                                              ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/spirit/home/support/attributes.hpp:309:13: note: 
      in instantiation of template class 'boost::is_convertible<foo,
      boost::fusion::vector<std::__1::vector<char, std::__1::allocator<char> >,
      std::__1::basic_string<char> > >' requested here
          : is_convertible<Attribute, Expected>
            ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/mpl/aux_/nested_type_wknd.hpp:27:7: note: 
      in instantiation of template class
      'boost::spirit::traits::detail::attribute_is_compatible<boost::fusion::vector<std::__1::vector<char,
      std::__1::allocator<char> >, std::__1::basic_string<char> >, foo>'
      requested here
    : T::type
      ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/mpl/aux_/preprocessed/gcc/or.hpp:51:11: note: 
      (skipping 12 contexts in backtrace; use -ftemplate-backtrace-limit=0 to
      see all)
          BOOST_MPL_AUX_NESTED_TYPE_WKND(T1)::value
          ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/mpl/aux_/nested_type_wknd.hpp:38:24: note: 
      expanded from macro 'BOOST_MPL_AUX_NESTED_TYPE_WKND'
    ::boost::mpl::aux::nested_type_wknd<T> \
                       ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/function/function_template.hpp:1072:5: note: 
      in instantiation of function template specialization
      'boost::function3<bool,
      boost::spirit::karma::detail::output_iterator<std::__1::back_insert_iterator<std::__1::basic_string<char>
      >, mpl_::int_<15>, boost::spirit::unused_type> &,
      boost::spirit::context<boost::fusion::cons<const foo &,
      boost::fusion::nil_>, boost::fusion::vector<> > &, const
      boost::spirit::karma::any_space<boost::spirit::char_encoding::standard>
      &>::function3<boost::spirit::karma::detail::generator_binder<boost::spirit::karma::alternative<boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::plus<boost::spirit::karma::any_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type> >,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>, boost::fusion::nil_> > > > >,
      boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::omit_directive<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, false>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, boost::fusion::nil_> > >,
      boost::fusion::nil_> > >, mpl_::bool_<false> > >' requested here
    base_type(f)
    ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/function/function_template.hpp:1125:5: note: 
      in instantiation of function template specialization 'boost::function<bool
      (boost::spirit::karma::detail::output_iterator<std::__1::back_insert_iterator<std::__1::basic_string<char>
      >, mpl_::int_<15>, boost::spirit::unused_type> &,
      boost::spirit::context<boost::fusion::cons<const foo &,
      boost::fusion::nil_>, boost::fusion::vector<> > &, const
      boost::spirit::karma::any_space<boost::spirit::char_encoding::standard>
      &)>::function<boost::spirit::karma::detail::generator_binder<boost::spirit::karma::alternative<boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::plus<boost::spirit::karma::any_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type> >,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>, boost::fusion::nil_> > > > >,
      boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::omit_directive<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, false>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, boost::fusion::nil_> > >,
      boost::fusion::nil_> > >, mpl_::bool_<false> > >' requested here
    self_type(f).swap(*this);
    ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/spirit/home/karma/nonterminal/rule.hpp:192:19: note: 
      in instantiation of function template specialization 'boost::function<bool
      (boost::spirit::karma::detail::output_iterator<std::__1::back_insert_iterator<std::__1::basic_string<char>
      >, mpl_::int_<15>, boost::spirit::unused_type> &,
      boost::spirit::context<boost::fusion::cons<const foo &,
      boost::fusion::nil_>, boost::fusion::vector<> > &, const
      boost::spirit::karma::any_space<boost::spirit::char_encoding::standard>
      &)>::operator=<boost::spirit::karma::detail::generator_binder<boost::spirit::karma::alternative<boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::plus<boost::spirit::karma::any_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type> >,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>,
      boost::fusion::cons<boost::spirit::karma::literal_char<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type, true>, boost::fusion::nil_> > > > >,
      boost::fusion::cons<boost::spirit::karma::sequence<boost::fusion::cons<boost::spirit::karma::omit_directive<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, false>,
      boost::fusion::cons<boost::spirit::karma::any_string<boost::spirit::char_encoding::standard,
      boost::spirit::unused_type>, boost::fusion::nil_> > >,
      boost::fusion::nil_> > >, mpl_::bool_<false> > >' requested here
            lhs.f = detail::bind_generator<Auto>(
                  ^
/Users/mcdanb/Build/ng-core-Debug/API/inc/boost/spirit/home/karma/nonterminal/rule.hpp:201:13: note: 
      in instantiation of function template specialization
      'boost::spirit::karma::rule<std::__1::back_insert_iterator<std::__1::basic_string<char>
      >, foo (),
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
      boost::spirit::char_encoding::standard> >, 0>, boost::spirit::unused_type,
      boost::spirit::unused_type>::define<mpl_::bool_<false>,
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::bitwise_or,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::unary_plus,
      boost::proto::argsns_::list1<const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::char_,
      boost::spirit::char_encoding::standard> > &>, 1> &,
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<const char &>, 0> >, 2> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &,
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<const char &>, 0> >, 2> &, const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::subscript,
      boost::proto::argsns_::list2<const
      boost::spirit::terminal<boost::spirit::tag::skip> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &>, 2> >' requested here
            define<mpl::false_>(*this, expr, traits::matches<karma::doma...
            ^
karma-char-seq.cpp:24:13: note: in instantiation of function template
      specialization
      'boost::spirit::karma::rule<std::__1::back_insert_iterator<std::__1::basic_string<char>
      >, foo (),
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
      boost::spirit::char_encoding::standard> >, 0>, boost::spirit::unused_type,
      boost::spirit::unused_type>::rule<boost::proto::exprns_::expr<boost::proto::tagns_::tag::bitwise_or,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::unary_plus,
      boost::proto::argsns_::list1<const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::char_,
      boost::spirit::char_encoding::standard> > &>, 1> &,
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<const char &>, 0> >, 2> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &,
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
      boost::proto::argsns_::term<const char &>, 0> >, 2> &, const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,
      boost::proto::argsns_::list2<const
      boost::proto::exprns_::expr<boost::proto::tagns_::tag::subscript,
      boost::proto::argsns_::list2<const
      boost::spirit::terminal<boost::spirit::tag::skip> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &, const
      boost::spirit::terminal<boost::spirit::tag::char_code<boost::spirit::tag::string,
      boost::spirit::char_encoding::standard> > &>, 2> &>, 2> >' requested here
        =   +char_ << '(' << string << ')'
            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:489:40: note: 
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'const allocator_type' (aka 'const
      std::__1::allocator<char>') for 1st argument
    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
                                       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:501:14: note: 
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'size_type' (aka 'unsigned long') for
      1st argument
    explicit vector(size_type __n);
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:537:5: note: 
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'initializer_list<value_type>' (aka
      'initializer_list<char>') for 1st argument
    vector(initializer_list<value_type> __il);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:549:5: note: 
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'const std::__1::vector<char,
      std::__1::allocator<char> >' for 1st argument
    vector(const vector& __x);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:555:5: note: 
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'std::__1::vector<char,
      std::__1::allocator<char> >' for 1st argument
    vector(vector&& __x)
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:508:9: note: 
      candidate constructor template not viable: requires 2 arguments, but 1 was
      provided
        vector(_InputIterator __first,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:516:9: note: 
      candidate constructor template not viable: requires at least 3 arguments,
      but 1 was provided
        vector(_InputIterator __first, _InputIterator __last, const allo...
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:523:9: note: 
      candidate constructor template not viable: requires 2 arguments, but 1 was
      provided
        vector(_ForwardIterator __first,
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:530:9: note: 
      candidate constructor template not viable: requires at least 3 arguments,
      but 1 was provided
        vector(_ForwardIterator __first, _ForwardIterator __last, const ...
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:483:5: note: 
      candidate constructor not viable: requires 0 arguments, but 1 was provided
    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:503:14: note: 
      candidate constructor not viable: requires 2 arguments, but 1 was provided
    explicit vector(size_type __n, const allocator_type& __a);
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:505:5: note: 
      candidate constructor not viable: requires 2 arguments, but 1 was provided
    vector(size_type __n, const_reference __x);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:539:5: note: 
      candidate constructor not viable: requires 2 arguments, but 1 was provided
    vector(initializer_list<value_type> __il, const allocator_type& __a);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:550:5: note: 
      candidate constructor not viable: requires 2 arguments, but 1 was provided
    vector(const vector& __x, const allocator_type& __a);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:562:5: note: 
      candidate constructor not viable: requires 2 arguments, but 1 was provided
    vector(vector&& __x, const allocator_type& __a);
    ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:506:5: note: 
      candidate constructor not viable: requires 3 arguments, but 1 was provided
    vector(size_type __n, const_reference __x, const allocator_type& __a);
    ^
1 error generated.

The problem construct appears to be +char_. The error goes away if it is replaced with string; but the error also goes away if the alternative is removed from the rule.

This code worked fine with the Boost.Spirit.Karma included with Boost 1.62.0.

Attachments (1)

karma-char-seq.cpp (629 bytes ) - added by Braden McDaniel <braden@…> 6 years ago.
Example

Download all attachments as: .zip

Change History (3)

by Braden McDaniel <braden@…>, 6 years ago

Attachment: karma-char-seq.cpp added

Example

comment:1 by Braden McDaniel <braden@…>, 5 years ago

Version: Boost 1.63.0Boost 1.64.0

Still a problem in Boost 1.64.0.

comment:2 by Braden McDaniel <braden@…>, 5 years ago

Component: spiritfusion
Note: See TracTickets for help on using tickets.