I want to configure iwyu to analyze the head file in a recursive way. It seems only one layer head file is be analyzed. I apologize if it is a stuip problem. I have a test case to demonstrate this.
// A.h
#ifndef A_H
#define A_H
class A
{
};
#endif
// B.h
#ifndef B_H
#define B_H
#include "A.h"
class B
{
public:
A a;
};
#endif
// C.h
#ifndef C_h
#define C_h
#include "B.h" // I think do not need to include A.h, because A.h already be included by B.h
class C
{
A a;
B b;
};
#endif
// C.cpp
#include "C.h"
void printC(C c)
{
}
# compile_commands.json
[
{
"directory": ".",
"command": "g++ -c C.cpp",
"file": "C.cpp"
}
]
I think in C.h
do not need to include A.h
, because C.h
already include B.h
, A.h
already be include by B.h
.
However, when I using iwyu, with version include-what-you-use 0.9 based on clang version 5.0.1-2 (tags/RELEASE_501/final)
, with command iwyu_tool -p .
, the result showns that
C.h should add these lines:
#include "A.h" // for A
C.h should remove these lines:
The full include-list for C.h:
#include "A.h" // for A
#include "B.h" // for B
---
(C.cpp has correct #includes/fwd-decls)
I can not understand why, or do I do something wrong? Thanks for your time.