Open
Description
Somewhat related to a recent post on R-devel, some users will still try to use Rf_error()
in C++ code using Rcpp. However, (as is documented) C++ destructors won't run when a longjmp occurs in cases like this. For example:
#include <Rcpp.h>
using namespace Rcpp;
struct A {
A() { Rprintf("A()\n"); }
~A() { Rprintf("~A()\n"); }
};
// [[Rcpp::export]]
SEXP uhoh() {
A a;
Rf_error("Oops!");
}
/*** R
uhoh()
*/
In this example, ~A()
is never printed.
We could consider masking the definition of Rf_error()
in these contexts. For example, something like:
#define Rf_error(...) \
static_assert(false, "Use of Rf_error() in C++ contexts is unwise: consider using Rcpp::stop() instead.");
There might also be a way to provide our own definition of Rf_error()
that "masks" the version provided by R, but I wasn't able to find something immediately obvious.
Metadata
Metadata
Assignees
Labels
No labels