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

オープン 初心者向け
#1,537 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
90/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
r
領域
backend

調査の方向性

inst/include/Rcpp/vector/const_string_proxy.h から始めます。ここでは、4 つの非 const の operator== と operator!= のオーバーロードが、string_proxy.h の対応する演算子と異なっています。Apple clang 14 および 17 を使い、C++17 と C++20 のモードで issue の Rcpp::export の例をコンパイルして実行します。issue に示されたすべての const_Proxy の比較が、曖昧なオーバーロードのエラーなくコンパイルされ、既存の比較動作が保たれたら完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
796
フォーク
217
平均マージ
1日 12時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

RcppCore/Rcpp のほかの issue

RcppCore/Rcpp の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。