Message-ID: <5b1d8b001a8a42ac8c639e610cb37ddb@fu-berlin.de>
Date: 2024-12-18T18:46:15Z
From: Bielow, Chris
Subject: [R-pkg-devel] use of assert in C++
In-Reply-To: <f78e3e990156453da4ef5f85befca7fe@fu-berlin.de>
Dear all,
hoping this is the right place for this:
I stumbled upon documentation regarding the use of `assert` in C++ code, in
particular, https://cran.r-project.org/web/packages/policies.html states
that
```
Thus C/C++ calls to assert/abort/exit/std::terminate, Fortran calls to STOP
and so on must be avoided.
```
, which goes against all best practice guidelines I'm aware of.
Therefore I would propose to remove 'assert' from the above statement.
In support, https://cran.r-project.org/doc/manuals/r-release/R-exts.html
states that
```
One usage that could call abort is the assert macro in C or C++ functions,
which should never be active in production code. The normal way to ensure
that is to define the macro NDEBUG, and R CMD INSTALL does so as part of the
compilation flags.
```
which seems a reasonable thing to do.
As a sidenote, the guide could be extended to encourage new mechanisms
available in modern C++ like `static_assert`.
Cheers
Chris