Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ambiguous < operation for logical (compiler error) #263

Open
vspinu opened this issue Feb 18, 2022 · 2 comments
Open

Ambiguous < operation for logical (compiler error) #263

vspinu opened this issue Feb 18, 2022 · 2 comments
Labels
feature a feature request or enhancement

Comments

@vspinu
Copy link
Contributor

vspinu commented Feb 18, 2022

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>
@vspinu
Copy link
Contributor Author

vspinu commented Feb 18, 2022

Relatedly automatic promotion to double does not work:

void c_test(cpp11::logicals t1, cpp11::logicals t2) {
  /* std::min(t1[0],t2[0]); */
  double x = t1[0];
}
//    error: conversion from ‘cpp11::r_bool’ to ‘double’ is ambiguous

@vspinu
Copy link
Contributor Author

vspinu commented Feb 18, 2022

Other missing methods on r_bool and double +=, -=, -, *=, *.

Not sure what to do with this. This limitation inhibits development of generic code on doubles, integers and logicals simultaneously.

@romainfrancois romainfrancois added the feature a feature request or enhancement label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants