Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive when included header has incorrect includes #926

Closed
ptomato opened this issue May 30, 2021 · 2 comments
Closed

False positive when included header has incorrect includes #926

ptomato opened this issue May 30, 2021 · 2 comments
Milestone

Comments

@ptomato
Copy link

ptomato commented May 30, 2021

I've found a minimal example for a case where an included header's missing include is reported as an IWYU error in the .cpp file. (In my case, the equivalents of b.h and c.h are library headers, so I get an IWYU error in my code and can't easily change the library headers to have correct includes.)

a.cpp:

#include "c.h"

void a(C c) {
    c.method(42);
}

b.h:

#pragma once
#include <utility>
void b(int&& i);

c.h:

#pragma once
#include "b.h"

struct C {
  template <typename T>
  void method(T&& t) {
    return b(std::forward<T>(t));
  }
};

Command line:

$ include-what-you-use a.cpp 

a.cpp should add these lines:
#include <utility>  // for forward

a.cpp should remove these lines:

The full include-list for a.cpp:
#include <utility>  // for forward
#include "c.h"      // for C
---

Here, c.h should #include <utility> and b.h should not, but IWYU should not suggest anything to be changed in a.cpp.

@kimgr
Copy link
Contributor

kimgr commented Jul 31, 2021

I just tried to repro this (sorry about the long delay) -- I suspected it had something to do with other problems around templates and std::move -- but it actually seems to work on mainline. I'm not quite sure what fixed it.

@ptomato Any chance you could take the latest IWYU for a spin with the code that triggered this originally? Thanks.

@ptomato
Copy link
Author

ptomato commented Jul 31, 2021

Yes, this seems to have been fixed on the latest git commit, I don't get the error anymore with the original code either. Thanks.

@ptomato ptomato closed this as completed Jul 31, 2021
@kimgr kimgr added this to the iwyu 0.17 milestone Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants