r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
199 stars 46 forks source link

Incompatible with `[[nodiscard]]` attribute #240

Closed nx10 closed 2 years ago

nx10 commented 2 years ago

cpp11 seems to be incompatible with the [[nodiscard]] attribute of C++17:

cpp11::cpp_function('[[nodiscard]] int add(int x, int y, int z) {
  int sum = x + y + z;
  return sum;
}', cxx_std = "CXX17")
Error: cpp11 attributes must be either `cpp11::register` or `cpp11::init`:
- Invalid attribute `nodiscard` on
line 5 in file [...]

If I use cpp11::cpp_register() in my package it throws errors for each function that is tagged with [[nodiscard]], even though they are not also tagged with cpp11::register or cpp11::init. Would it be possible for cpp11 to ignore [[nodiscard]] (or all unknown attributes)?

Thank you for your time!

Tested with: cpp11 version 0.3.1 R version 4.1.1 Windows 10 64bit

jimhester commented 2 years ago

Thanks for opening the issue, this is fixed in the devel version of cpp11, but not yet on CRAN.

nx10 commented 2 years ago

Great! Thank you for your quick response.