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

yytext is already defined #933

Closed
Myushu opened this issue Jan 23, 2018 · 4 comments
Closed

yytext is already defined #933

Myushu opened this issue Jan 23, 2018 · 4 comments
Assignees
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@Myushu
Copy link

Myushu commented Jan 23, 2018

Hi,

We are trying to use your library on our project, which already contains 2 parsers generated by bison/flex. We have an issue during compilation because of the yytext variable. See the following clang output:

nlohmann/json.hpp:2870:17: error: expected ';' at end of declaration list
    std::string yytext {};
                ^
CustomLanguageParser.cpp: note: expanded from macro 'yytext'
#define yytext yyg->yytext_r
                  ^

We previously had a similar issue while implementing the 2 parsers (used to parse custom languages), there was a conflict in-between the yytext variable of each parser, which was resolved by using the %prefix 'directive' (See the StackOverflow answer here). This solved our issue until we tried to use your library in our codebase, which raised new errors (conflicts in-between your variable and the parsers #define) about the yytext variable.

For now we are completely stuck as the only solution we found was renaming your yytext variable, which doesn't seems like an acceptable fix to us. Did we miss something or are we the first one to use your library in a codebase already containing bison/flex generated parsers ?

infos:

  • clang: Apple LLVM version 9.0.0 (clang-900.0.39.2)
  • flex: 2.6
  • bison: 3.0
  • nlohmann/json: 3.0.1

Thanks

@nlohmann
Copy link
Owner

Indeed you may be the first to do so, and since I used flex in the past, I decided to call the token buffer yytext. I think it would not be a problem for me to change the name of the variable.

(Just to make sure - would it be possible to #undef yytext before including json.hpp?)

@nlohmann
Copy link
Owner

It is really strange that the macro from flex leaks into other code.

@nlohmann
Copy link
Owner

I cannot reproduce the issue, and I think this is an issue with flex/bison to define macros without undefining them.

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Jan 28, 2018
@theodelrieu
Copy link
Contributor

Agreed, but I think we should still rename the variable. It's the same thing as the min/max Microsoft macros, it's annoying but we must workaround it...

@nlohmann nlohmann removed the state: needs more info the author of the issue needs to provide more details label Jan 29, 2018
@nlohmann nlohmann self-assigned this Jan 29, 2018
@nlohmann nlohmann added this to the Release 3.1.0 milestone Jan 29, 2018
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jan 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants