Issue 1087 in include-what-you-use: IWYU should not suggest adding two copies of the same header

0 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Jul 24, 2022, 11:29:23 PMJul 24
to include-wh...@googlegroups.com
New issue 1087 by ptomato: IWYU should not suggest adding two copies of the same header
https://github.com/include-what-you-use/include-what-you-use/issues/1087

It can happen, when using e.g. a precompiled header, that IWYU suggests adding the same header in both quotes and angle brackets. This seems undesirable.

Minimal reproducer:

**a.cpp:**
```c++
#include "a.h"
void foo() {}
```
**a.h:**
```c++
#pragma once
void foo();
```
**b.h:** (the "precompiled" header)
```c++
#include <a.h>
```
Output:
```
$ include-what-you-use -I. -include b.h a.cpp

(a.h has correct #includes/fwd-decls)

a.cpp should add these lines:
#include <a.h>

a.cpp should remove these lines:

The full include-list for a.cpp:
#include <a.h>
#include "a.h" // for foo
---
```

I'm guessing it's because `b.h` includes the header in angle brackets already, so IWYU decides it's a system header, but somehow even though it does realize `"a.h"` is already included (it says, `for foo`) it doesn't realize that `<a.h>` needn't be included to provide `foo`.


notifi...@include-what-you-use.org

unread,
Jul 25, 2022, 1:32:51 PMJul 25
to include-wh...@googlegroups.com
Comment #0 on issue 1087 by kimgr: IWYU should not suggest adding two copies of the same header
https://github.com/include-what-you-use/include-what-you-use/issues/1087

The angle/quote curse strikes again. I wonder if you can work around this using the `--prefix_header_includes` switch?


notifi...@include-what-you-use.org

unread,
Jul 25, 2022, 11:45:03 PMJul 25
to include-wh...@googlegroups.com
Comment #2 on issue 1087 by ptomato: IWYU should not suggest adding two copies of the same header
https://github.com/include-what-you-use/include-what-you-use/issues/1087

Thanks for the suggestion. `--prefix_header_includes=keep` seems to fix it for some of my files, but not all.


Reply all
Reply to author
Forward
0 new messages