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

Compilation error when trying to pass both any& dt and an output param to peg::parser::parse() #270

Closed
curldivergence opened this issue Mar 14, 2023 · 2 comments

Comments

@curldivergence
Copy link

Hi! First of all, thank you for such an outstanding library :)
But unfortunately, I faced a compilation problem today: as mentioned in the title, I've tried to use the overload of peg::parser::parse() that accepts both an std::any& dt and an output parameter T& (my use case is such that in dt I'm trying to pass my symbol table to the semantic actions, and in the output parameter I'm passing the root of my AST).
The compilation error consists in the inability to bind a temporary to a non-const reference:

In file included from /Users/andrew/Dev/cpp-peglib/test/test1.cc:2:
/Users/andrew/Dev/cpp-peglib/test/../peglib.h:4542:27: error: non-const lvalue reference to type 'Definition::Result' cannot bind to a temporary of type 'peg::Definition::Result'
                          rule.parse_and_get_value(s, n, dt, val, path, log_));
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/andrew/Dev/cpp-peglib/test/../peglib.h:4564:12: note: in instantiation of function template specialization 'peg::parser::parse_n<int>' requested here
    return parse_n(sv.data(), sv.size(), dt, val, path);
           ^
/Users/andrew/Dev/cpp-peglib/test/test1.cc:223:10: note: in instantiation of function template specialization 'peg::parser::parse<int>' requested here
  parser.parse("42", dt, output);
         ^
/Users/andrew/Dev/cpp-peglib/test/../peglib.h:4662:66: note: passing argument to parameter 'r' here
  bool post_process(const char *s, size_t n, Definition::Result &r) const {

I've put together a minimal test and committed it here, so may I ask you to kindly have a look and give a bit advice regarding dealing with this? :) Maybe I'm doing something wrong on my side?

Thank you!

@yhirose
Copy link
Owner

yhirose commented Mar 15, 2023

@curldivergence thank you for the report! I fixed it in peglib.h.

@curldivergence
Copy link
Author

@yhirose Thank you very much for such a quick fix!

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

2 participants