cmake4eclipse icon indicating copy to clipboard operation
cmake4eclipse copied to clipboard

Wrong header indexed in case of multiple header files located at different paths

Open gentooise opened this issue 6 years ago • 2 comments

This is a...

  • [X] Bug Report
  • [ ] Enhancement Request

Brief Description

Wrong header parsed by CDT Indexer in case of multiple headers located at different paths but having the same file name.

Brief Summary

For a cross-platform C/C++ project I have the following file structure inside src folder:

/src/platform1/myheader.h
/src/platform1/mysource.cpp
/src/platform2/myheader.h
/src/platform2/mysource.cpp

where the platform is selected using multiple Build Configurations (i.e. passing different args to CMake).

Given that:

  • all the builds (and JSON files) are correct (e.g. when building for platform1 only /src/platform1/mysource.cpp is included in the build);
  • the Preprocessor Include Paths, Macros etc. menu shows correct Parser entries (e.g. only /src/platform1 if I'm working on platform1);

I see that, when opening /src/platform1/mysource.cpp file, I get Codan errors which are clearly related to /src/platform2/myheader.h (e.g. uninitialized member variable which is only declared in /src/platform2/myheader.h and not in /src/platform1/myheader.h). I think this is a bug, but I'm not sure if Indexer or plugin fault.

It is strange because when I Ctrl-click on #include "myheader.h" inside cpp file, eclipse seems to always open the correct platform-specific file. So, why does the Indexer consider the wrong header file if it's not even part of the include paths?

What is the expected behavior?

When selected Build Configuration is platform1, I would expect the Indexer to only parse header files contained into /src/platform1 (the only path present as Parser entry).

What behavior are you observing?

The Indexer seems to also parse header files not contained in any entry of the CMAKE_EXPORT_COMPILE_COMMANDS Parser, although I have set the following configuration:

image image

Useful Information

  • cmake4eclipse version: snapshot-5 from issue 117
  • Which OS do you use: Windows 10 64bit
  • Cmake version: 3.15.0

I could try to build a minimal project to reproduce the issue if necessary.

gentooise avatar Sep 16 '19 12:09 gentooise

I see that, when opening /src/platform1/mysource.cpp file, I get Codan errors which are clearly related to /src/platform2/myheader.h (e.g. uninitialized member variable which is only declared in /src/platform2/myheader.h and not in /src/platform1/myheader.h). I think this is a bug, but I'm not sure if Indexer or plugin fault.

cmake4eclipse adds the include paths it find in the compile_commands.json file only. So I think this is a CDT issue or an issue with your cmake scripts.

I could try to build a minimal project to reproduce the issue if necessary.

Yes please.

15knots avatar Sep 21 '19 17:09 15knots

Yes please.

Unfortunately I'm not able to reproduce the issue with a very simple project. For some reason, the Indexer seems to get confused only with large projects. However, it seems the issue is well-known (see here).

The only way to avoid this is to exclude resources from the project, and it would be useful to have it automatic (which takes me to this other issue I upvoted here).

gentooise avatar Oct 10 '19 07:10 gentooise