Skip to content

Instantly share code, notes, and snippets.

@shyouhei
Last active July 28, 2022 18:51
Show Gist options
  • Save shyouhei/5bf8847933edf7c9f9d23017c1418ed6 to your computer and use it in GitHub Desktop.
Save shyouhei/5bf8847933edf7c9f9d23017c1418ed6 to your computer and use it in GitHub Desktop.
include-what-you-use is a garbage.

For instance when we have the following C file:

#include <time.h>
struct tm x;

iwyu generates the following garbage output:

zsh % iwyu 99-tmp.c

99-tmp.c should add these lines:
#include <bits/types/struct_tm.h>  // for tm

99-tmp.c should remove these lines:
- #include <time.h>  // lines 1-1

The full include-list for 99-tmp.c:
#include <bits/types/struct_tm.h>  // for tm
---
[1]    12133 exit 4     iwyu tmp.c

Which is totally nonsense. <time.h> is defined to have struct tm in ISO C since forever (cf: ISO/IEC 9899:2018 section 7.27).

struct tm is not the only entity that iwyu miss; for another instance max_align_t is missing. Not to mention other entities in POSIX and C++.

This tool is worse than being useless. The suggestion miserably breaks portability. Just trash it.

#include <time.h>
struct tm x;
@shyouhei
Copy link
Author

In order for iwyu to become a non-toy, IMO it should leave all #include <foo> -style lines as-is and focus on #include "foo", or at least understand #pragma gcc system_header to ignore symbols from such files.

@michpolicht
Copy link

It's another boilerplate party. Completely useless, upside-down "solution" for something that should be well-handled by automated tools without programmer being involved in typing some stupid directives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment