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

Offen Anfängerfreundlich
#1,537 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
1/5
Geschätzter Aufwand
Unter einer Stunde
Anfängerfreundlichkeit
90/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
r
Bereich
backend

Rechercherichtung

Beginne mit inst/include/Rcpp/vector/const_string_proxy.h, wo sich die vier nicht-const operator==- und operator!=-Überladungen von den entsprechenden Operatoren in string_proxy.h unterscheiden. Kompiliere und führe die Rcpp::export-Beispiele des Issues unter Apple clang 14 und 17 in den Modi C++17 und C++20 aus. Erledigt ist, wenn alle im Issue gezeigten const_Proxy-Vergleiche ohne Fehler wegen mehrdeutiger Überladungen kompilieren und das bestehende Vergleichsverhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
C++
Sterne
796
Forks
217
Ø Merge
1 T. 12 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus RcppCore/Rcpp

Alle Issues in RcppCore/Rcpp

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.