Defining the following function:
Rcpp::sourceCpp(code = '//[[Rcpp::export]]
void foo(const char* a = "(", const char* b= ")") {}')
gives:
file8586f8153c2.cpp: In function ‘SEXPREC* sourceCpp_63_foo(SEXP)’:
file8586f8153c2.cpp:12:10: error: call of overloaded ‘foo(Rcpp::traits::input_parameter<const char*>::type&)’ is ambiguous
12 | foo(a);
| ^
file8586f8153c2.cpp:2:6: note: candidate: ‘void foo(const char*, const char*)’
2 | void foo(const char* a = "(", const char* b= ")") {}
| ^~~
file8586f8153c2.cpp:7:6: note: candidate: ‘void foo(const char*)’
7 | void foo(const char* a);
| ^~~
make: *** [/usr/lib64/R/etc/Makeconf:176: file8586f8153c2.o] Error 1
g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"/home/pr228844/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I"/tmp/RtmpTogNDM/sourceCpp-x86_64-pc-linux-gnu-1.0.1" -D_FORTIFY_SOURCE=2 -fpic -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -c file8586f8153c2.cpp -o file8586f8153c2.o
Error in Rcpp::sourceCpp(code = "//[[Rcpp::export]]\nvoid foo(const char* a = \"(\", const char* b= \")\") {}") :
Error 1 occurred building shared library.
Inverting the default values, leads to the same error:
Rcpp::sourceCpp(code = '//[[Rcpp::export]]
void foo(const char* a = ")", const char* b= "(") {}')
Replacing one of the default values with another value, remove the error:
Rcpp::sourceCpp(code = '//[[Rcpp::export]]
void foo(const char* a = "x", const char* b= "(") {}')
I think this is a bug in the hand-rolled C++ parser used for attributes. Since this is somewhat of an edge case, it's unlikely we'll fix this quickly -- but pull requests are welcome!
Seconded. I glanced iinto src/attributes.cpp but didn't find the regexp immediately. Sounds entirely fixable with a bit of patience so contributions welcome...
There's no regex, it's just a lookahead tokenizer. We have some logic to
exclude e.g. commas within quotes but I don't know if this can be easily
extended to parentheses. Would indeed be happy to review a PR.
On Tue, Jul 9, 2019 at 5:01 PM Dirk Eddelbuettel notifications@github.com
wrote:
Seconded. I glanced iinto src/attributes.cpp but didn't find the regexp
immediately. Sounds entirely fixable with a bit of patience so
contributions welcome...—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/RcppCore/Rcpp/issues/975?email_source=notifications&email_token=AAAZPR2UVB4OOZJB55IIQXLP6T4DFA5CNFSM4H7C3XYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZRQSOQ#issuecomment-509806906,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAZPRZWPRSJU6VKAGGHDW3P6T4DFANCNFSM4H7C3XYA
.
I've made the corrections and am going to make a pull request.
Thanks for the PR and the tests!