Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Enchufa2
Copy link
Member

First step to #1247

  • Add a message at compilation time, no masking yet
  • Protect the valid Rf_error calls generated by Rcpp

Checklist

  • Code compiles correctly
  • R CMD check still passes all tests
  • Preferably, new tests were added which fail without the change
  • Document the changes by file in ChangeLog

* Add a message at compilation time
* Protect the valid Rf_error calls generated by Rcpp
Copilot finished reviewing on behalf of Enchufa2 November 12, 2025 17:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR lays the groundwork for masking unsafe Rf_error() calls by introducing a macro that generates compilation messages warning users to use Rcpp::stop() instead. This is the first step toward addressing issue #1247.

  • Adds a new macro header file that redefines Rf_error() to emit a compilation warning message
  • Protects legitimate Rf_error() calls in Rcpp-generated code using parentheses (Rf_error)() to bypass the macro
  • Provides an opt-out mechanism via RCPP_NO_MASK_RF_ERROR for false positives

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
inst/include/Rcpp/macros/mask.h New file introducing the Rf_error macro that shows a compilation message directing users to Rcpp::stop()
inst/include/RcppCommon.h Includes the new mask.h header file at the end of the common includes
src/attributes.cpp Protects auto-generated Rf_error call with parentheses to prevent macro expansion
inst/tinytest/cpp/stack.cpp Protects test code's Rf_error call with parentheses and updates copyright
inst/tinytest/testRcppInterfaceExporter/src/RcppExports.cpp Protects auto-generated Rf_error call with parentheses
ChangeLog Documents all changes made in this PR

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Also better than my PR where @copilot always finds a typo to nag about.

@Enchufa2
Copy link
Member Author

So, as discussed, and the revdep machine made it clear, we cannot generate a note. Pragma messages are considered statements by gcc (see e.g. here and bugs linked there). Options are: be silent, or generate a warning without replacing.

In order to ask CRAN about what they think, we need to calculate how many packages would generate this warning. An upper bound was provided here by just grepping the sources of all reverse dependencies: 263 packages. From these, only 24 would also fail compilation or checks as documented in #1406. To further refine this list, we could collect the install logs and grep for the pragma (are they in the revdep machine from the previous run?).

#ifndef RCPP_NO_MASK_RF_ERROR
#define Rf_error(...) \
_Pragma("message \"Use of Rf_error() instead of Rcpp::stop(). Calls \
_Pragma("GCC warning \"Use of Rf_error() instead of Rcpp::stop(). Calls \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters either way but in RcppArmadillo I used #pragma message. Kurt was able to filter these with a heads-up. That would be one softer than a warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same. _Pragma expands into #pragma. It's the way to insert pragmas with preprocessor macros, because # has another meaning there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants