cpp_source fails to compile indented void-returning function
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
Research direction
Start by reproducing the failure with cpp11::cpp_source using the inline snippets, then compare it with the equivalent external-file case. Trace how cpp11 identifies the void return type and generates the wrapper, focusing on the leading space before the function declaration. Done means indented void-returning functions compile successfully in both inline and external-source cases.
Written by the indexing model from the issue text.
Description
If a void-returning function marked with cpp11::register is indented, cpp11 fails to recognize the void return type and will try to use its result in the wrapper it generates.
# This works
cpp11::cpp_source(code = "[[cpp11::register]]\nvoid foo() {}")
# This fails to compile. Note the extra space character between the newline and void
cpp11::cpp_source(code = "[[cpp11::register]]\n void foo() {}")
using C++ compiler: ‘g++ (GCC) 14.2.1 20241116’
using C++11
/tmp/nix-shell.Cz8fPO/RtmpadKzBh/code_16bff7617b36f0.cpp:2:11: warning: ‘cpp11::register’ scoped attribute directive ignored [-Wattributes]
2 | void foo() {}
| ^
/tmp/nix-shell.Cz8fPO/RtmpadKzBh/file16bff7121f1a99/src/cpp11.cpp: In function ‘SEXPREC* _code_16bff7617b36f0_foo()’:
/tmp/nix-shell.Cz8fPO/RtmpadKzBh/file16bff7121f1a99/src/cpp11.cpp:7:30: error: invalid use of void expression
7 | return cpp11::as_sexp(foo());
| ~~~^~
make: *** [/nix/store/bb3gfb6b740ha50bbwvbgslybnqm0vgf-R-4.4.3/lib/R/etc/Makeconf:204: /tmp/nix-shell.Cz8fPO/RtmpadKzBh/file16bff7121f1a99/src/cpp11.o] Error 1
Error: Compilation failed.
The same behaviour happens when using an external file instead of an inline code = argument.
packageVersion("cpp11")
#> [1] ‘0.5.2’
- Dominant language
- C++
- Stars
- 224
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from r-lib/cpp11
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·