Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting parenthesis characters as default value to function parameters yields a compiling error #975

Closed
pkrog opened this issue Jul 9, 2019 · 5 comments

Comments

@pkrog
Copy link
Contributor

pkrog commented Jul 9, 2019

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= "(") {}')
@kevinushey
Copy link
Contributor

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!

@eddelbuettel
Copy link
Member

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...

@jjallaire
Copy link
Member

jjallaire commented Jul 9, 2019 via email

@pkrog
Copy link
Contributor Author

pkrog commented Jul 18, 2019

I've made the corrections and am going to make a pull request.

@eddelbuettel
Copy link
Member

Thanks for the PR and the tests!

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

No branches or pull requests

4 participants