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

String literal macro value not correctly parsed from compile_commands.json #133

Open
baldapps opened this issue May 11, 2020 · 4 comments
Open
Labels
not a bug here not a bug here. CDT or CMake bug

Comments

@baldapps
Copy link

Consider a very simple project with a CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
set(MY_VERSION 01.00)
set(MY_MINOR_VERSION 1)
set(MY_COMP ${MY_VERSION}-${MY_MINOR_VERSION})
cmake_policy(SET CMP0048 NEW)
project(FOO CXX)
add_executable(FOO main.cpp)
add_definitions(-DFOO_VERSION="${MY_COMP}")

In the compile_commands.json I see with three slashes:

-DFOO_VERSION=\"01.00-1\"

In Eclipse I see

int main() {
std::cout << FOO_VERSION << std::endl; <------Bad character sequence encountered:
return 0;
}

So it seems when the macro is parsed in Eclipse an extra slash is taken into account. No problem executing the simple program.

@15knots
Copy link
Owner

15knots commented May 11, 2020

Bad character sequence encountered

Where does that message come from?
Is it an error message of the C++ compiler? Or is it displayed when you hover over the macro name?

@baldapps
Copy link
Author

Compiler Is not involved, it's a message you see while you hover with the mouse on the macro name. It's a parser/indexer Eclipse message.

@15knots 15knots changed the title String not correctly parsed in Eclipse String literal macro value not correctly parsed from compile_commands.json May 11, 2020
@15knots
Copy link
Owner

15knots commented May 11, 2020

I can see that the vaule of FOO_VERSIOn comes in as \"01.00-1\".
Should be "01.00-1".
So either the json parser is buggy or the generated compile_commands.json .

@15knots
Copy link
Owner

15knots commented May 12, 2020

According to json.org only a single backslash is required to escape a quotation mark.
Cmake generates three backslashes instead.

So please file a change request on the cmake site since other tools might suffer from that issue, too.

@15knots 15knots added the not a bug here not a bug here. CDT or CMake bug label Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug here not a bug here. CDT or CMake bug
Projects
None yet
Development

No branches or pull requests

2 participants