Issue 1093 in include-what-you-use: stddef.h recommended in C++ code

Skip to first unread message

Aug 9, 2022, 8:37:47 AM8/9/22
New issue 1093 by martingalvan-nordic: stddef.h recommended in C++ code

Hi, I'm running an IWYU I built manually from the clang_14 branch (--version shows include-what-you-use 0.18 (git:abd5d2b) based on Ubuntu clang version 14.0.6-++20220622053131+f28c006a5895-1~exp1~20220622173215.157). OS is Ubuntu 20.04.

I noticed that IWYU is recommending `#include <stddef.h>` for `size_t` in .cpp files. I'm invoking it through CMake as follows:

`/usr/bin/cmake -E __run_co_compile --iwyu="/usr/local/bin/include-what-you-use;-Xiwyu;--cxx17ns;-Xiwyu;--no_fwd_decls;-Xiwyu;--mapping_file=/usr/local/bin/../share/include-what-you-use/stl.c.headers.imp;--driver-mode=g++" <other args come here>`

You can see that I'm explicitly including the stl.c.headers.imp mapping file (I don't know whether the mappings provided by IWYU are used by default). However, I still see stddef.h being recommended instead of cstddef. Am I doing something wrong?

Aug 9, 2022, 1:08:58 PM8/9/22
Comment #1 on issue 1093 by kimgr: stddef.h recommended in C++ code

I can confirm that the equivalent of `stl.c.headers.imp` is baked into IWYU by default.

IWYU mappings are not keyed by language, so the expectation that `size_t` should come from `<cstddef>` for C++ and `<stddef.h>` for C unfortunately does not hold.

Perhaps you could add an additional mapping file that just says `<stddef.h>` (private) is mapped to `<cstddef.h>` (public). Or, alternatively, provide an override symbol mapping from `size_t` (private) to `<cstddef>` (public). Though I suspect both of those will fail due to artificial constraints in IWYU.

I see there's a public-to-public mapping from `<stddef.h>` to `<cstddef>`, which I think means `<cstddef>` is accepted as a stand-in for `<stddef.h>`. So if you were to search-and-replace `<stddef.h>` to `<cstddef>` manually, at least IWYU should leave the existing code alone. Try on one file first to verify.

Reply all
Reply to author
0 new messages