Originally reported on Google Code with ID 73
What steps will reproduce the problem? Give the *exact* arguments passed
to include-what-you-use, and attach the input source file that gives the
problem (minimal test-cases are much appreciated!)
A.h:
"""
class A {};
"""
B.h:
"""
#include "A.h"
class B : public A {};
"""
test.cpp:
"""
#include "B.h"
int main() {
A a;
B b;
return &a && &b ? 123 : -123;
}
"""
Program execution and output:
"""
$ /tmp/llvm/Release+Asserts/bin/include-what-you-use test.cpp
test.cpp should add these lines:
#include "A.h" // for A
test.cpp should remove these lines:
The full include-list for test.cpp:
#include "A.h" // for A
#include "B.h" // for B
---
"""
What is the expected output? What do you see instead?
The only reason it asks me to include A.h is for the variable of type A. But we already
have a variable of type B, and B.h must already include the full class declaration
of A, because B is derived from A. This shouldn't be considered bootlegging -- there
is no possible way that B.h will ever not include A.h unless the include hierarchy
changes, which in many cases it never will. I think this takes "no bootlegging" too
far, and results in lots of unnecessary proliferation of header files.
What version of the product are you using? On what operating system?
LLVM r160007, iwyu r357, Ubuntu 12.04 LTS x86.
Please provide any additional information below.
This is something I noticed while running iwyu on Mozilla's codebase. It would ask
me to include a lot of clearly pointless header files, like adding nsIDOMRange.h when
nsRange.h is already included, and the whole point of nsRange is to be the class that
implements the nsIDOMRange interface. There are lots of examples like this in the
Gecko codebase, probably in part because we have way too many useless abstract base
classes!
Reported by ayg.name on 2012-07-11 08:15:27
该提问来源于开源项目:include-what-you-use/include-what-you-use