Skip to content

const_string_proxy comparisons are ambiguous with Apple clang (non-const operator== / operator!=) #1537

In progress

Description

@s-u

Comparing two CharacterVector::const_Proxy values does not compile with Apple clang 14 in C++20 mode, and
comparing a const_Proxy with a SEXP does not compile with Apple clang 14 or 17.

#include <Rcpp.h>

// [[Rcpp::export]]
bool same(const Rcpp::CharacterVector x) {
    Rcpp::CharacterVector::const_Proxy a = x[0], b = x[1];
    return a == b;                                          // ambiguous: clang 14, C++20
}

// [[Rcpp::export]]
bool sx(const Rcpp::CharacterVector x, SEXP s) {
    Rcpp::CharacterVector::const_Proxy a = x[0];
    return a == s || a != s;                                // ambiguous: clang 14 and 17, C++17 and C++20
}
error: use of overloaded operator '==' is ambiguous (with operand types
  'Rcpp::CharacterVector::const_Proxy' (aka 'const_string_proxy<16, Rcpp::PreserveStorage>') and
  'Rcpp::CharacterVector::const_Proxy')

In inst/include/Rcpp/vector/const_string_proxy.h the const char* and const const_string_proxy&
overloads of operator== and operator!= are not declared const, while the SEXP overloads and all the corresponding operators in string_proxy.h, are.

Adding const to those four operators resolves all of the above (also in PR):

@@ -97,17 +97,17 @@ namespace internal{
 		inline bool empty() const { return *begin() == '\0' ; }
 		inline reference operator[]( R_xlen_t n ){ return *( begin() + n ) ; }
 
-		bool operator==( const char* other){
+		bool operator==( const char* other) const {
 			return strcmp( begin(), other ) == 0 ;
 		}
-		bool operator!=( const char* other){
+		bool operator!=( const char* other) const {
 			return strcmp( begin(), other ) != 0 ;
 		}
 
-		bool operator==( const const_string_proxy& other){
+		bool operator==( const const_string_proxy& other) const {
 			return strcmp( begin(), other.begin() ) == 0 ;
 		}
-		bool operator!=( const const_string_proxy& other){
+		bool operator!=( const const_string_proxy& other) const {
 			return strcmp( begin(), other.begin() ) != 0 ;
 		}
 

Affected CRAN packages that fail to install for this reason: comparator, IFC, IsoSpecR,
packcircles, runner.

Seen with R 4.6.1, Rcpp 1.1.2, Apple clang 14.0.3. The operators are unchanged in current Rcpp master (279801e, 1.1.2.8), where Apple clang 17.0.0 (arm64) gives the same SEXP errors but accepts same(). With the changes above the example compiles in both modes with both compilers.

Activity

  1. eddelbuettel commented on Nov 29, 2026

    @eddelbuettel
    Member

    Thanks, I have no doubt this helps on the systems you tested. It would be helpful if you could also toss it at a Linux version or two (in a container for overall ease) to ensure it leaves no hiccups there either (as I noted in the corresponding PR #1538 you kindly made).

    Appreciate the issue and PR.

  2. added a commit that references this issue on Nov 29, 2026
  3. s-u commented on Nov 29, 2026

    @s-u
    Author

    GH actions worked but also tested on:

    Debian testing │ g++ 16.2.0   │ OK │ 1838 pass
    Debian testing │ clang 23.1.6 │ OK │ 1838 pass
    Ubuntu 26.04   │ g++ 15.2.0   │ OK │ 1838 pass
    Ubuntu 26.04   │ clang 22.1.2 │ OK │ 1838 pass
    Fedora rawhide │ g++ 16.2.1   │ OK │ 1838 pass
    Fedora rawhide │ clang 23.1.6 │ OK │ 1838 pass
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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