Skip to content

iwyu: --check_also=*.h ? #329

Open
Open

Description

@maflcko

Copied from a review comment:

The CI runs IWYU and it only audits "the input .cc file and its associated .h files" (e.g. foo.cpp also checks foo.h). type-string.h has no matching .cpp so it isn't audited.

-  set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error")
+  set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error;-Xiwyu;--check_also=${PROJECT_SOURCE_DIR}/include/mp/*.h")

With the above diff it checks the headers too and can check for type-string.h. (Bitcoin core also uses --check_also for primitive headers):

/home/vinicius/Code/my/libmultiprocess/include/mp/type-string.h should add these lines:
#include <string>     // for string
namespace mp { struct InvokeContext; }

/home/vinicius/Code/my/libmultiprocess/include/mp/type-string.h should remove these lines:
- #include <ranges>  // lines 11-11

It also flag a lot of what there is currently (10+ header files) and can also make false positives: note the #include <variant> // for tuple which doens't make sense for proxy-io.h:

/home/vinicius/Code/my/libmultiprocess/include/mp/proxy-io.h should add these lines:
#include <capnp/capability.h>          // for Capability, CallContext, Capab...
#include <capnp/common.h>              // for Void, word
#include <capnp/message.h>             // for MallocMessageBuilder, ReaderOp...
#include <capnp/rpc-twoparty.capnp.h>  // for VatId, Side, Side_9fd69ebc87b9...
#include <capnp/rpc.h>                 // for RpcSystem, makeRpcClient, make...
#include <kj/async-io.h>               // for LowLevelAsyncIoProvider, Async...
#include <kj/async-prelude.h>          // for ReadyNow
#include <kj/async.h>                  // for TaskSet, Promise, READY_NOW
#include <kj/common.h>                 // for mv, ArrayPtr, KJ_IF_MAYBE, Maybe
#include <kj/exception.h>              // for runCatchingExceptions, Exception
#include <kj/memory.h>                 // for Own, heap
#include <kj/string.h>                 // for KJ_STRINGIFY, StringPtr
#include <list>                        // for _List_iterator, list, _List_co...
#include <tuple>                       // for tuple
#include <utility>                     // for forward, move
#include <variant>                     // for tuple
#include <vector>                      // for vector
namespace mp { class Connection; }
namespace mp { class EventLoop; }
namespace mp { template <typename Interface> struct ProxyClient; }
namespace mp { template <typename Interface> struct ProxyServer; }

So I believe this isn't a one line fix, it would require a one-time PR to manually audit and fix and map the false positives in a mapping file and then enabling --check_also and --mapping_file with the mapping file to handle false positives on the CI. Maybe this is not worth effort.

This is just what I found poking around, if there's a better way id like to hear it.

Originally posted by @ViniciusCestarii in #307 (comment)

Activity

  1. hebasto commented on Aug 2, 2026

    @hebasto
    Member

    It ... can also make false positives:

    CI currently uses include-what-you-use 0.24. Bumping to 0.26 would pull in several bug fixes.

  2. maflcko commented on Aug 2, 2026

    @maflcko
    ContributorAuthor

    It ... can also make false positives:

    CI currently uses include-what-you-use 0.24. Bumping to 0.26 would pull in several bug fixes.

    I tried the bump in #296

  3. maflcko commented on Nov 10, 2026

    @maflcko
    ContributorAuthor

    #296 was merged, so the false-postives should have gone away, but I haven't tried this myself yet.

  4. ViniciusCestarii commented on Nov 10, 2026

    @ViniciusCestarii
    Contributor

    Tried it with v0.26 but it still seems to get some false positives (same "should add #include <variant> // for tuple in proxy-io.h" ). Also tried v0.27 and it fix some false positive but not all. I guess if we really want to check mp/ headers it is necessary to build our own mapping file excluding false positives

  5. hebasto commented on Nov 10, 2026

    @hebasto
    Member

    Tried it with v0.26 but it still seems to get some false positives (same "should add #include <variant> // for tuple in proxy-io.h" ).

    See include-what-you-use/include-what-you-use#2084. Fixed in include-what-you-use/include-what-you-use#2093.

  6. ViniciusCestarii commented on Nov 10, 2026

    @ViniciusCestarii
    Contributor

    Can confirm that v0.27 includes the fix and it does't show "should add #include // for tuple in proxy-io.h".

    v0.27 also included some new changes that shows some new lines that doesn't look right:

    • With IWYU pragma: export on forward declarations, proxy.h is told to #include "mp/proxy.h"(itself)
    • headers that already have #include <mp/proxy.h> are told to add #include "mp/proxy.h" too.

    I created issue for it here: include-what-you-use/include-what-you-use#2165.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions