Skip to content

Compilation error with clang/libc++ and std::equal() on CharacterVectors #854

@lionel-

Description

@lionel-

This pattern recently started to cause CRAN failures in purrrlyr on the fedora/clang machine. I can reproduce it with clang on my macOS machine:

#include <algorithm>
#include <Rcpp.h>

// [[Rcpp::export]]
bool test(Rcpp::CharacterVector x, Rcpp::CharacterVector y) {
  if (x.length() != y.length()) {
    return 0;
  }

  return std::equal(x.begin(), x.end(), y.begin());
}


/*** R
  test("foo", "bar")
*/
In file included from clangCharacterVector.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:682:71: error: use of overloaded operator '==' is ambiguous (with operand types 'const Rcpp::internal::string_proxy<16, PreserveStorage>' and 'const Rcpp::internal::string_proxy<16, PreserveStorage>')
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
                                                                  ~~~ ^  ~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:1325:14: note: in instantiation of member function 'std::__1::__equal_to<Rcpp::internal::string_proxy<16, PreserveStorage>, Rcpp::internal::string_proxy<16, PreserveStorage> >::operator()' requested here
        if (!__pred(*__first1, *__first2))
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:1337:19: note: in instantiation of function template specialization 'std::__1::equal<Rcpp::internal::Proxy_Iterator<Rcpp::internal::string_proxy<16, PreserveStorage> >, Rcpp::internal::Proxy_Iterator<Rcpp::internal::string_proxy<16, PreserveStorage> >, std::__1::__equal_to<Rcpp::internal::string_proxy<16, PreserveStorage>, Rcpp::internal::string_proxy<16, PreserveStorage> > >' requested here
    return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
                  ^
clangCharacterVector.cpp:10:15: note: in instantiation of function template specialization 'std::__1::equal<Rcpp::internal::Proxy_Iterator<Rcpp::internal::string_proxy<16, PreserveStorage> >, Rcpp::internal::Proxy_Iterator<Rcpp::internal::string_proxy<16, PreserveStorage> > >' requested here
  return std::equal(x.begin(), x.end(), y.begin());
              ^
/Users/lionel/R/library/3.5/Rcpp/include/Rcpp/vector/string_proxy.h:204:22: note: candidate function
                bool operator==( SEXP other ) const {
                     ^
/Users/lionel/R/library/3.5/Rcpp/include/Rcpp/String.h:525:17: note: candidate function
    inline bool operator==(const String::StringProxy& lhs, const String& rhs) {
                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:682:71: note: built-in candidate operator==(struct SEXPREC *, struct SEXPREC *)
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
                                                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:682:71: note: built-in candidate operator==(const struct SEXPREC *, const struct SEXPREC *)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:682:71: note: built-in candidate operator==(char *, char *)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:682:71: note: built-in candidate operator==(const char *, const char *)
1 error generated.
make: *** [clangCharacterVector.o] Error 1
ccache clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Users/lionel/R/library/3.5/Rcpp/include" -I"/Users/lionel/Dropbox/Projects/R/mock/clangCharacterVector/.metadata" -I"/Users/lionel/Dropbox/Projects/R/mock/clangCharacterVector/.metadata/../inst/include" -I/usr/local/include   -fPIC  -arch x86_64  -ftemplate-depth-256  -Wall  -pedantic  -O0 -g -c clangCharacterVector.cpp -o clangCharacterVector.o
Error in Rcpp::sourceCpp("~/Dropbox/Projects/R/mock/clangCharacterVector/.metadata/clangCharacterVector.cpp") : 
  Error 1 occurred building shared library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions