`const_string_proxy` comparisons are ambiguous with Apple clang (non-const `operator==` / `operator!=`)
还没有人认领这个 Issue。
评估
调研方向
从 inst/include/Rcpp/vector/const_string_proxy.h 开始,其中四个非 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 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RcppCore/Rcpp 的其他 Issue
-
难度 4/5 一周以上 新手友好度 15/100
-
难度 4/5 3-5 天 新手友好度 35/100
-
no-issue-activity
难度 5/5 一周以上 新手友好度 25/100
-
Consider masking definition of Rf_error()?可能已有人在做 @Enchufa2 于 396 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 30/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
godotengine/godot#125913 ·
维护者通常 1 天内回复
-
期待增加虚线线条样式未关闭
难度 2/5 1-3 小时 新手友好度 62/100
-
bug
难度 1/5 1 小时以内 新手友好度 94/100
vllm-project/vllm#70568 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
mw00/project-maya#1368 ·
维护者通常 2 天内回复
-
needs triage
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复