odbc icon indicating copy to clipboard operation
odbc copied to clipboard

Package C++ code fails to compile due to invalid static_cast in nanodbc.cpp

Open alexkyllo opened this issue 3 years ago • 0 comments

Issue Description and Expected Result

I was trying to build this package locally to see if I can work on a fix for #299. I didn't find any specific instructions here for how to compile the package's C++ code, so I just tried devtools::load_all(). It fails with the below compilation error on both my Ubuntu and Windows machines, and it appears to be an invalid cast from nanodbc::connection to bool at https://github.com/r-dbi/odbc/blob/main/src/nanodbc/nanodbc.cpp#L3467. When I comment out that assert, it compiles successfully and I can run the tests. I would expect it to compile without having to do that, though. Did I do something wrong? Or does this code only compile on an older GCC version or something? (Looks like I have 10.3)

Re-compiling odbc
-  installing *source* package 'odbc' ...
   ** using staged installation
   ** libs
   g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.1/include" -DNDEBUG  -I'C:/Users/jekyllo/AppData/Local/R/win-library/4.2/Ro   g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.1/include" -DNDEBUG  -I'C:/Users/jekyllo/AppData/Local/R/win-library/4.2/Ro   g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-42~1.1/include" -DNDEBUG  -I'C:/Users/jekyllo/AppData/Local/R/win-library/4.2/Ro   In file included from c:\rtools42\x86_64-w64-mingw32.static.posix\lib\gcc\x86_64-w64-mingw32.static.posix\10.3.0\inc,                    from nanodbc/nanodbc.cpp:33:
   nanodbc/nanodbc.cpp: In function 'std::__cxx11::list<nanodbc::data_source> nanodbc::list_data_sources()':
   nanodbc/nanodbc.cpp:34:30: error: no match for 'operator!' (operand type is 'nanodbc::connection')
      34 | #define NANODBC_ASSERT(expr) assert(expr)
         |                              ^~~~~~
   nanodbc/nanodbc.cpp:3467:9: note: in expansion of macro 'NANODBC_ASSERT'
    3467 |         NANODBC_ASSERT(env);
         |         ^~~~~~~~~~~~~~
   nanodbc/nanodbc.cpp:34:30: note: candidate: 'operator!(bool)' (built-in)
      34 | #define NANODBC_ASSERT(expr) assert(expr)
         |                              ^~~~~~
   nanodbc/nanodbc.cpp:3467:9: note: in expansion of macro 'NANODBC_ASSERT'
    3467 |         NANODBC_ASSERT(env);
         |         ^~~~~~~~~~~~~~
   nanodbc/nanodbc.cpp:34:30: note:   no known conversion for argument 1 from 'nanodbc::connection' to 'bool'
      34 | #define NANODBC_ASSERT(expr) assert(expr)
         |                              ^~~~~~
   nanodbc/nanodbc.cpp:3467:9: note: in expansion of macro 'NANODBC_ASSERT'
    3467 |         NANODBC_ASSERT(env);
         |         ^~~~~~~~~~~~~~
   make: *** [Makevars.win:17: nanodbc.o] Error 1
   ERROR: compilation failed for package 'odbc'
-  removing 'C:/Users/jekyllo/AppData/Local/Temp/RtmpE3Ta7t/devtools_install_1cf442b29be/odbc'
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, ...`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---

Database

N/A

Reproducible Example

devtools::load_all()

-->

Session Info
devtools::session_info()
#> - Session info -------------------------------------------------------------------------------------------------------
 setting  value
 version  R version 4.2.1 (2022-06-23 ucrt)
 os       Windows 10 x64 (build 22621)
 system   x86_64, mingw32
 ui       RTerm
 language (EN)
 collate  English_United States.1252
 ctype    English_United States.1252
 tz       America/Los_Angeles
 date     2022-10-15
 pandoc   2.19.2 @ C:\\PROGRA~1\\Pandoc\\pandoc.exe

- Packages -----------------------------------------------------------------------------------------------------------
 ! package     * version    date (UTC) lib source
   bit           4.0.4      2020-08-04 [1] CRAN (R 4.2.1)
   bit64         4.0.5      2020-08-30 [1] CRAN (R 4.2.1)
   blob          1.2.3      2022-04-10 [1] CRAN (R 4.2.1)
   brio          1.1.3      2021-11-30 [1] CRAN (R 4.2.1)
   cachem        1.0.6      2021-08-19 [1] CRAN (R 4.2.1)
   callr         3.7.2      2022-08-22 [1] CRAN (R 4.2.1)
   cli           3.4.1      2022-09-23 [1] CRAN (R 4.2.1)
   crayon        1.5.2      2022-09-29 [1] CRAN (R 4.2.1)
   DBI           1.1.3      2022-06-18 [1] CRAN (R 4.2.1)
   desc          1.4.2      2022-09-08 [1] CRAN (R 4.2.1)
   devtools      2.4.5      2022-10-11 [1] CRAN (R 4.2.1)
   digest        0.6.29     2021-12-01 [1] CRAN (R 4.2.1)
   ellipsis      0.3.2      2021-04-29 [1] CRAN (R 4.2.1)
   fansi         1.0.3      2022-03-24 [1] CRAN (R 4.2.1)
   fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.2.1)
   fs            1.5.2      2021-12-08 [1] CRAN (R 4.2.1)
   glue          1.6.2      2022-02-24 [1] CRAN (R 4.2.1)
   hms           1.1.2      2022-08-19 [1] CRAN (R 4.2.1)
   htmltools     0.5.3      2022-07-18 [1] CRAN (R 4.2.1)
   htmlwidgets   1.5.4      2021-09-08 [1] CRAN (R 4.2.1)
   httpuv        1.6.5      2022-01-05 [1] CRAN (R 4.2.1)
   later         1.3.0      2021-08-18 [1] CRAN (R 4.2.1)
   lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.2.1)
   magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.2.1)
   memoise       2.0.1      2021-11-26 [1] CRAN (R 4.2.1)
   mime          0.12       2021-09-28 [1] CRAN (R 4.2.0)
   miniUI        0.1.1.1    2018-05-18 [1] CRAN (R 4.2.1)
 R odbc        * 1.3.3.9000 <NA>       [?] <NA>
   pillar        1.8.1      2022-08-19 [1] CRAN (R 4.2.1)
   pkgbuild      1.3.1      2021-12-20 [1] CRAN (R 4.2.1)
   pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.2.1)
   pkgload       1.3.0      2022-06-27 [1] CRAN (R 4.2.1)
   prettyunits   1.1.1      2020-01-24 [1] CRAN (R 4.2.1)
   processx      3.7.0      2022-07-07 [1] CRAN (R 4.2.1)
   profvis       0.3.7      2020-11-02 [1] CRAN (R 4.2.1)
   promises      1.2.0.1    2021-02-11 [1] CRAN (R 4.2.1)
   ps            1.7.1      2022-06-18 [1] CRAN (R 4.2.1)
   purrr         0.3.5      2022-10-06 [1] CRAN (R 4.2.1)
   R6            2.5.1      2021-08-19 [1] CRAN (R 4.2.1)
   Rcpp          1.0.9      2022-07-08 [1] CRAN (R 4.2.1)
   remotes       2.4.2      2021-11-30 [1] CRAN (R 4.2.1)
   rlang         1.0.6      2022-09-24 [1] CRAN (R 4.2.1)
   rprojroot     2.0.3      2022-04-02 [1] CRAN (R 4.2.1)
   rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.2.1)
   sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.2.1)
   shiny         1.7.2      2022-07-19 [1] CRAN (R 4.2.1)
   stringi       1.7.8      2022-07-11 [1] CRAN (R 4.2.1)
   stringr       1.4.1      2022-08-20 [1] CRAN (R 4.2.1)
   testthat    * 3.1.5      2022-10-08 [1] CRAN (R 4.2.1)
   tibble        3.1.8      2022-07-22 [1] CRAN (R 4.2.1)
   urlchecker    1.0.1      2021-11-30 [1] CRAN (R 4.2.1)
   usethis       2.1.6      2022-05-25 [1] CRAN (R 4.2.1)
   utf8          1.2.2      2021-07-24 [1] CRAN (R 4.2.1)
   vctrs         0.4.2      2022-09-29 [1] CRAN (R 4.2.1)
   withr         2.5.0      2022-03-03 [1] CRAN (R 4.2.1)
   xtable        1.8-4      2019-04-21 [1] CRAN (R 4.2.1)

 [1] C:/Users/jekyllo/AppData/Local/R/win-library/4.2
 [2] C:/Program Files/R/R-4.2.1/library

alexkyllo avatar Oct 15 '22 15:10 alexkyllo