Why does assert not work here?
^ Apparently, Rcpp has a habit of defining NDEBUG
on its own, even if not defined by myself.
m@m-X555LJ:~/wtfdir$ cat WTF.r
#!/usr/bin/Rscript
library(Rcpp)
sourceCpp("WTF.cpp")
m@m-X555LJ:~/wtfdir$ cat WTF.cpp
#ifdef NDEBUG
#error WTF I did not define this
#endif
m@m-X555LJ:~/wtfdir$ ./WTF.r
WTF.cpp:2:2: error: #error WTF I did not define this
#error WTF I did not define this
^~~~~
make: *** [WTF.o] Error 1
g++ -I"/usr/share/R/include" -DNDEBUG -I"/home/m/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I"/home/m/wtfdir" -fpic -g -O2 -fdebug-prefix-map=/build/r-base-3U0YWo/r-base-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c WTF.cpp -o WTF.o
/usr/lib/R/etc/Makeconf:172: recipe for target 'WTF.o' failed
Error in sourceCpp("WTF.cpp") : Error 1 occurred building shared library.
Execution halted
m@m-X555LJ:~/wtfdir$
The answers to the SO question I linked to explain that (a) It is prohibited to call assert
in packages uploaded to CRAN, because (b) C++ code should not halt R code and (c) I should throw exceptions instead, which are caught by Rcpp.
However:
- I do not wish to upload my code to CRAN; instead, I'm writing the code for my own use;
- Even if I wished to upload it to CRAN, I could compile it myself without
NDEBUG
for testing purposes and then defineNDEBUG
just before uploading to CRAN; - Since both R code as well as C++ code is written by myself for the same purpose (and I consider them both to be the same program), I would actually like the whole program to blow if a bug in any part of it is detected; continuing running R code if C++ code is faulty is pointless for me;
- Since I did not know
NDEBUG
would be defined, I already have put quite a fewassert
s in my code and also printing diagnostics viastd::cerr
is wrapped in#ifndef NDEBUG
s; these fail to work obviously; - I don't want to unconditionally throw exceptions since some
assert
s are computation heavy; - As of now, my C++ code blows my R code anyway because it crashes, I'm trying to investigate the issue but I can't because my diagnostics don't work.
Is there any way to make Rcpp stop defining NDEBUG
? Or am I supposed to simply remove all asserts
and anything else that depends on NDEBUG
and switch to throwing exceptions and stop complaining?