Bug 485013 - Organize includes: problem with include paths
Summary: Organize includes: problem with include paths
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-refactoring (show other bugs)
Version: 8.8.0   Edit
Hardware: All All
: P3 normal with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-30 07:36 EST by Mathias Kunter CLA
Modified: 2020-09-04 15:21 EDT (History)
4 users (show)

See Also:


Attachments
Example Eclipse C++ project demonstrating the problem (6.44 KB, application/zip)
2017-04-26 04:39 EDT, Notify Me CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Kunter CLA 2015-12-30 07:36:07 EST
The organize includes feature apparently always assumes that preprocessor include paths are external include paths.


Steps to reproduce:

1) Add the following include path to a C++ project: go to Project Properties -> C/C++ Build -> Settings -> Tool Settings tab -> G++ Compiler -> Includes -> Include paths -> Add -> click on Workspace button -> select project root folder.


2) Use the organize includes feature with default settings for the following minimal test.cpp file:

*** FILE: test.h ***
class TestClass { };

*** FILE: test.cpp ***
void f() { TestClass test; }


3) Observe behavior:
Expected: test.h is included as partner header, using #include "test.h"
Actual: test.h is included as system header, using #include <test.h>

The problem is that organize includes classifies test.h as system header here instead of as partner header. Thus, I can't include my headers by using a project-root relative include path.


4) Proposed solution:
Only classify header files as system headers if they're not contained within the project itself, independent of any include paths.
Comment 1 Nathan Ridge CLA 2016-01-05 02:02:40 EST
Confirmed. Interestingly, if the path is added via Project Properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Entries -> GNU C++ -> CDT User Setting Entries (as a Workspace Path), the generated include is of the form "test.h".
Comment 2 Notify Me CLA 2017-04-26 04:39:35 EDT
Created attachment 267996 [details]
Example Eclipse C++ project demonstrating the problem

This problem still exists and is very annoying!

I added a test project that reproduces the problem.
It has the following classes:
- TestIncludeeA
- Level1Folder/TestIncludeeB
- Path/To/Class/Deepdownbelow/TestIncluder

The TestIncluder includes the TestIncludeeA and B, which are several folders up in the project tree. The includes generated by eclipse look like the following:

#include "../../../../Level1Folder/TestIncludeeB.h"
#include "../../../../TestIncludeeA.h"


I hope this helps fixing the problem.