problem using boost::trim() with std::u16string with NDK16 - CLANG + c++_static

266 views
Skip to first unread message

Tsvetan Bogoev

unread,
Nov 22, 2017, 5:21:55 AM11/22/17
to android-ndk
Hi, trying to use boost::trim() with std::u16string gives a compilation error

environment: Android NDK 16, clang +  c++_static, boost verison is 1.65.1 (same with older versions like 1.59)
here is the code:

#include <boost/algorithm/string.hpp>
#include <string>
...
std
::u16string str; //using std::string is fine
boost
::trim(str);

the error:

In file included from jni/main.cpp:4:
In file included from /home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string.hpp:19:
In file included from /home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:23:
In file included from /home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/classification.hpp:18:
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/classification.hpp:45:73: error: implicit instantiation of undefined template 'std::__ndk1::ctype<char32_t>'
                    return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
                                                                        ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/trim.hpp:53:27: note: in instantiation of function template specialization 'boost::algorithm::detail::is_classifiedF::operator()<char32_t>' requested here
                    if ( !IsSpace(*(--It)) )
                          ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/trim.hpp:86:52: note: in instantiation of function template specialization 'boost::algorithm::detail::trim_end_iter_select<std::__ndk1::__wrap_iter<char32_t *>, boost::algorithm::detail::is_classifiedF>' requested here
                return ::boost::algorithm::detail::trim_end_iter_select( InBegin, InEnd, IsSpace, category() );
                                                   ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:237:45: note: in instantiation of function template specialization 'boost::algorithm::detail::trim_end<std::__ndk1::__wrap_iter<char32_t *>, boost::algorithm::detail::is_classifiedF>' requested here
                ::boost::algorithm::detail::trim_end(
                                            ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:360:33: note: in instantiation of function template specialization 'boost::algorithm::trim_right_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_right_if( Input, IsSpace );
                                ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:375:33: note: in instantiation of function template specialization 'boost::algorithm::trim_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_if(
                                ^
jni/main.cpp:21:12: note: in instantiation of function template specialization 'boost::algorithm::trim<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> > >' requested here
    boost::trim(u16str);
           ^
/home/tsvetan/devToolsLinux/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/__locale:453:52: note: template is declared here
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
                                                   ^
/home/tsvetan/devToolsLinux/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/__locale:212:54: error: implicit instantiation of undefined template 'std::__ndk1::ctype<char32_t>'
    return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
                                                     ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/classification.hpp:45:33: note: in instantiation of function template specialization 'std::__ndk1::use_facet<std::__ndk1::ctype<char32_t> >' requested here
                    return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
                                ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/trim.hpp:53:27: note: in instantiation of function template specialization 'boost::algorithm::detail::is_classifiedF::operator()<char32_t>' requested here
                    if ( !IsSpace(*(--It)) )
                          ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/trim.hpp:86:52: note: in instantiation of function template specialization 'boost::algorithm::detail::trim_end_iter_select<std::__ndk1::__wrap_iter<char32_t *>, boost::algorithm::detail::is_classifiedF>' requested here
                return ::boost::algorithm::detail::trim_end_iter_select( InBegin, InEnd, IsSpace, category() );
                                                   ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:237:45: note: in instantiation of function template specialization 'boost::algorithm::detail::trim_end<std::__ndk1::__wrap_iter<char32_t *>, boost::algorithm::detail::is_classifiedF>' requested here
                ::boost::algorithm::detail::trim_end(
                                            ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:360:33: note: in instantiation of function template specialization 'boost::algorithm::trim_right_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_right_if( Input, IsSpace );
                                ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:375:33: note: in instantiation of function template specialization 'boost::algorithm::trim_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_if(
                                ^
jni/main.cpp:21:12: note: in instantiation of function template specialization 'boost::algorithm::trim<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> > >' requested here
    boost::trim(u16str);
           ^
/home/tsvetan/devToolsLinux/android-ndk-r16/sources/cxx-stl/llvm-libc++/include/__locale:453:52: note: template is declared here
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
                                                   ^
In file included from jni/main.cpp:4:
In file included from /home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string.hpp:19:
In file included from /home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:22:
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/trim.hpp:69:26: error: no matching function for call to object of type 'boost::algorithm::detail::is_classifiedF'
                    if (!IsSpace(*It))
                         ^~~~~~~
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:128:45: note: in instantiation of function template specialization 'boost::algorithm::detail::trim_begin<std::__ndk1::__wrap_iter<char32_t *>, boost::algorithm::detail::is_classifiedF>' requested here
                ::boost::algorithm::detail::trim_begin(
                                            ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:361:33: note: in instantiation of function template specialization 'boost::algorithm::trim_left_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_left_if( Input, IsSpace );
                                ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/trim.hpp:375:33: note: in instantiation of function template specialization 'boost::algorithm::trim_if<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> >, boost::algorithm::detail::is_classifiedF>' requested here
            ::boost::algorithm::trim_if(
                                ^
jni/main.cpp:21:12: note: in instantiation of function template specialization 'boost::algorithm::trim<std::__ndk1::basic_string<char32_t, std::__ndk1::char_traits<char32_t>, std::__ndk1::allocator<char32_t> > >' requested here
    boost::trim(u16str);
           ^
/home/tsvetan/work/OfficeCppWin/libs/vendor/boost/boost/algorithm/string/detail/classification.hpp:43:22: note: candidate template ignored: substitution failure [with CharT = char32_t]
                bool operator()( CharT Ch ) const
                     ^
3 errors generated.
make: *** [obj/local/armeabi-v7a/objs-debug/main/main.o] Error 1

Tsvetan Bogoev

unread,
Nov 22, 2017, 1:54:55 PM11/22/17
to android-ndk
I just saw, that error message was produced by using u32string (insteat of tus16string), but its the same problem.

Ryan Prichard

unread,
Nov 23, 2017, 9:03:35 AM11/23/17
to andro...@googlegroups.com
Boost is doing something like this:

    #include <cstdio>
    #include <locale>
    
    template <typename CharT>
    bool is_space(CharT ch) {
      return std::use_facet<std::ctype<CharT>>(std::locale()).is(std::ctype_base::space, ch);
    }
    
    int main() {
      printf("%d\n", is_space<char16_t>(' '));
      printf("%d\n", is_space<char16_t>('x'));
      return 0;
    }

With libstdc++ (gnustl), this code crashes at run-time:

    terminate called after throwing an instance of 'std::bad_cast'
      what():  std::bad_cast
    Aborted (core dumped)

With libc++, it fails with the above compiler error: 

    implicit instantiation of undefined template 'std::__1::ctype<char32_t>'

This same problem happens on non-Android systems.

I think the C++ library is required to provide specializations of std::ctype for char and wchar_t, but not for other types. I don't know whether it makes sense to define std::ctype for the Unicode char types.

This StackOverflow post looks relevant: https://stackoverflow.com/a/41316811

-Ryan


On Wed, Nov 22, 2017 at 7:28 AM, Tsvetan Bogoev <tsvetan...@gmail.com> wrote:
I just saw, that error message was produced by using u32string (insteat of tus16string), but its the same problem.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/53d3c251-8b2c-47c1-93d3-35532ccf56ee%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages