Ambiguous < operation for logical (compiler error)

Open
#263 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, r
Domain
api, tooling

Research direction

Reproduce the supplied example with the compiler command and inspect cpp11/logicals.hpp, especially how cpp11::r_bool is compared during std::min. Resolve the ambiguity reported between the int and Rboolean operator< candidates; done when the example compiles without that error.

Written by the indexing model from the issue text.

Description

feature

With the following file

#include <cpp11.hpp>
#include <algorithm>

void c_test(cpp11::logicals t1, cpp11::logicals t2) {
  std::min(t1[0],t2[0]);
}

I get

> cpp11::cpp_source("/home/vspinu/dev/iroll/src/tmp.cpp", quiet = F, clean = F, dir = '/home/vspinu/Dropbox/dev/iroll/')

g++ -std=gnu++11 -I"/home/vspinu/bin/R-4.1.2-bin/include" -DNDEBUG -I'/home/vspinu/.lib/4.1.2/cpp11/include'  -I/usr/local/include   -fpic  -g -O2  -c /home/vspinu/Dropbox/dev/iroll/src/tmp.cpp -o /home/vspinu/Dropbox/dev/iroll/src/tmp.o
In file included from /usr/include/c++/7/algorithm:61:0,
                 from /home/vspinu/.lib/4.1.2/cpp11/include/cpp11/logicals.hpp:3,
                 from /home/vspinu/Dropbox/dev/iroll/src/tmp.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = cpp11::r_bool]’:
/home/vspinu/Dropbox/dev/iroll/src/tmp.cpp:6:23:   required from here
/usr/include/c++/7/bits/stl_algobase.h:200:15: error: ambiguous overload for ‘operator<’ (operand types are ‘const cpp11::r_bool’ and ‘const cpp11::r_bool’)
       if (__b < __a)
           ~~~~^~~~~
/usr/include/c++/7/bits/stl_algobase.h:200:15: note: candidate: operator<(int, int) <built-in>
/usr/include/c++/7/bits/stl_algobase.h:200:15: note: candidate: operator<(Rboolean, Rboolean) <built-in>
/home/vspinu/bin/R-4.1.2-bin/etc/Makeconf:177: recipe for target '/home/vspinu/Dropbox/dev/iroll/src/tmp.o' failed
make: *** [/home/vspinu/Dropbox/dev/iroll/src/tmp.o] Error 1
In file included from /usr/include/c++/7/algorithm:61:0,
                 from /home/vspinu/.lib/4.1.2/cpp11/include/cpp11/logicals.hpp:3,
                 from /home/vspinu/Dropbox/dev/iroll/src/tmp.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h: In instantiation of ‘const _Tp& std::min(const _Tp&, const _Tp&) [with _Tp = cpp11::r_bool]’:
/home/vspinu/Dropbox/dev/iroll/src/tmp.cpp:6:23:   required from here
/usr/include/c++/7/bits/stl_algobase.h:200:15: error: ambiguous overload for ‘operator<’ (operand types are ‘const cpp11::r_bool’ and ‘const cpp11::r_bool’)
       if (__b < __a)
           ~~~~^~~~~
/usr/include/c++/7/bits/stl_algobase.h:200:15: note: candidate: operator<(int, int) <built-in>
/usr/include/c++/7/bits/stl_algobase.h:200:15: note: candidate: operator<(Rboolean, Rboolean) <built-in>
make: *** [/home/vspinu/Dropbox/dev/iroll/src/tmp.o] Error 1
``` R version 4.1.2 (2021-11-01) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.6 LTS

Matrix products: default
BLAS: /home/vspinu/bin/R-4.1.2-bin/lib/libRblas.so
LAPACK: /home/vspinu/bin/R-4.1.2-bin/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=de_DE.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] cpp11_0.4.2

loaded via a namespace (and not attached):
[1] compiler_4.1.2

</details>
Dominant language
C++
Stars
224
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cpp11

All issues in r-lib/cpp11

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.