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

Aperta Adatta ai principianti
#1,537 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
90/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r
Ambito
backend

Direzione di ricerca

Inizia da inst/include/Rcpp/vector/const_string_proxy.h, dove i quattro overload non const di operator== e operator!= differiscono dagli operatori corrispondenti di string_proxy.h. Compila ed esegui gli esempi Rcpp::export dell'issue con Apple clang 14 e 17 nelle modalità C++17 e C++20. Il lavoro è completo quando tutti i confronti di const_Proxy mostrati nell'issue compilano senza errori di overload ambiguo, preservando il comportamento di confronto esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C++
Stelle
796
Fork
217
Merge medio
1g 12h
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di RcppCore/Rcpp

Tutte le issue di RcppCore/Rcpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.