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

IWYU wants to pull in iosfwd "for std" #1251

Closed
computerquip opened this issue Apr 29, 2023 · 4 comments
Closed

IWYU wants to pull in iosfwd "for std" #1251

computerquip opened this issue Apr 29, 2023 · 4 comments

Comments

@computerquip
Copy link

I'm not sure what this means. For every file that has an std type of any kind, it keeps wanting to pull in iosfwd "for std". What does this mean, what causes it, and what can I do about it?

@kilroyd
Copy link
Contributor

kilroyd commented Apr 29, 2023

It would help if you could specify the OS and compiler (i.e. standard libraries) that you're using, as well as IWYU version.

At a guess, does the code you are checking do using namespace std?

@computerquip
Copy link
Author

computerquip commented Apr 29, 2023

Sorry. I'm using Clang 16 from the LLVM APT repository on Ubuntu 18.04 with libgcc-s1 from the test tool repository (since the newer LLVM binaries require it and 18.04 is relatively old).

Also, yes, those files do use using namespace std. Is that the cause? I do have other headers that have std such as <string> if it's any consolation. What can I do about it?

@kilroyd
Copy link
Contributor

kilroyd commented Apr 30, 2023

those files do use using namespace std. Is that the cause?

Yes. using namespace std is a use of std, so IWYU is trying to ensure you have an appropriate include. The way it locates a header to satisfy the namespace use is not great. There's an existing issue #828 covering this, and I have PR #1213 open that tries to do better.

Note that there's specific advice against using namespace std in the C++ core guidelines (https://isocpp.org/wiki/faq/coding-standards "Should I use using namespace std in my code"). The advice is to either be explicit, or use using declarations (using std::vector) instead.

Hopefully my PR, or something similar can make it to IWYU 0.21

@computerquip-work
Copy link

Alright, I'll close this since it's at best a duplicate of another issue. Thanks for the response, that cleared up my confusion.

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

3 participants