Bug 572557 - Eclipse CDT indexer adding unwanted quotes to symbol
Summary: Eclipse CDT indexer adding unwanted quotes to symbol
Status: REOPENED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-indexer (show other bugs)
Version: 10.2.0   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-02 10:43 EDT by Jonathon Smith CLA
Modified: 2021-04-21 14:04 EDT (History)
2 users (show)

See Also:


Attachments
screenshot of what works for me (247.48 KB, image/png)
2021-04-02 16:50 EDT, Jonah Graham CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathon Smith CLA 2021-04-02 10:43:57 EDT
In a project, I am using separate header files to specify parameters for separate configurations. For example, config1.h and config2.h. I have created separate build configurations in Eclipse for each configuration and added symbol PARAM_H_FILE assigned either PARAM_H_FILE=config1.h or PARAM_H_FILE=config2.h in Eclipse as a defined symbol for the respective build configuration. In order to include this file, I have added the following lines to a common header file in the project, based on online guidance:

#define QT(filename)    #filename    //!< Convert filename to string
#define QUOTE(filename) QT(filename) //!< Expand filename string

// Include header file.
#include QUOTE(PARAM_H_FILE) // Include vehicle definitions


The MINGW GCC compiler expands this to #include "config1.h" or #include "config2.h" as desired and compiles with no errors or warnings. However, the Eclipse CDT indexer expands this to #include "\"config1.h\"" or #include "\"config1.h\"", resulting in detected errors any time the macros defined in config1.h or config2.h are referenced in the code.

Also, I found that if I replace the above code with the following, then Eclipse does not detect any errors, but the project compiles with errors:

#include PARAM_H_FILE // Include vehicle definitions

I have tried formatting the symbol definition as: PARAM_H_FILE=config1.h, PARAM_H_FILE='config1.h', PARAM_H_FILE='"config1.h"' and PARAM_H_FILE="config1.h" and nothing seems to work.

As a point of reference, I am using is MinGW.org GCC-8.2.0-5 in Windows and Eclipse IDE for C/C++ Developers, Version: 2019-06 (4.12.0).

It looks like this may be a bug encountered when the indexer encounters non-numeric pre-compiler definitions.
Comment 1 Jonah Graham CLA 2021-04-02 16:46:23 EDT
In a first attempt to reproduce this with current CDT code on my Linux machine I cannot do it.

If I hover over #include QUOTE(PARAM_H_FILE) then the macro expansion shows "hello.h" and it compiles without error too:

gcc -DPARAM_H_FILE=hello.h -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Bug572557.d" -MT"src/Bug572557.o" -o "src/Bug572557.o" "../src/Bug572557.c"

So either this is a Windows problem, older CDT problem, or I have not reproduced the problem fully.
Comment 2 Jonah Graham CLA 2021-04-02 16:50:29 EDT
Created attachment 286026 [details]
screenshot of what works for me

I tried with older Eclipse CDT and it worked on Linux. I'll try on Windows next, but for reference this screenshot shows how I have setup the project.

Please let me know how that may differ from how you have it setup.
Comment 3 Jonah Graham CLA 2021-04-02 16:55:34 EDT
Worked on Windows too.

I am happy to reopen the bug with more information on how to reproduce.
Comment 4 Jonathon Smith CLA 2021-04-21 11:51:06 EDT
Hi.  Thanks for checking on this.

After some further investigation, I found that this was being caused by "&quot;" being added before and after the value assigned to the symbol in the .cproject XML file.

For example:
<listOptionValue builtIn="false" value="&qout;VC_PARAM_H_FILE=pm_draco.h&qout;"/>

The quotation makred by "&quot;" was not visible in the Eclipse project properties.  This project was ported from older versions of Eclipse at various points, so this may have been placed there in an older version.

The only way that I was able to successfully remove it was by modifying the XML directly.  If it's easy enough, it may be helpful to modify the application to make it more forward-compatible.  However, the problem has been corrected in my case for now.
Comment 5 Jonah Graham CLA 2021-04-21 14:04:28 EDT
Thanks Jonathon for following up.

I still can't reproduce, even with trying to add the &quot; around the whole define, or just the value.

Also, for me the &quot; shows up as " in the UI.

I suspect there is still something wrong. Perhaps you can provide the exact contents of the .cdtproject file that causes the problem as unfortunately your example has a typo that means it won't even load the project (quot vs qout):

(In reply to Jonathon Smith from comment #4)
> <listOptionValue builtIn="false" value="&qout;VC_PARAM_H_FILE=pm_draco.h&qout;"/>

So, this still works for me, but I hope I can help you narrow it down so no one else has to have this problem.