Skip to content

Extend IWYU checks to headers without a matching .cc file #4581

Open

Description

@om7057

Context

While working on PR #4574, we found that sdk/include/opentelemetry/sdk/metrics/view/predicate_factory.h uses uint8_t without including <cstdint>. It compiled only because something else in the same translation unit happened to pull that header in transitively. This kind of bug is exactly what include-what-you-use (IWYU) checks are meant to catch, but it slipped through because this header has no matching .cc file of its own to anchor an IWYU check against.

Proposal

Look into extending the project's IWYU tooling/CI so that header-only files (headers with no corresponding .cc translation unit in the same directory) are also checked for missing or unnecessary includes, rather than relying on incidental coverage from whichever .cc file happens to include them first.

Related

Activity

  1. added
    needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.
    on Sep 16, 2026
  2. om7057 commented on Sep 16, 2026

    @om7057
    ContributorAuthor

    Thanks for the suggestion, @lalitb. Opening this to track it separately as discussed in #4574.

  3. marcalff commented on Sep 16, 2026

    @marcalff
    Member

    Fixing this is especially valuable for all the header only files under api.

    In my understanding, IWYU will work with the CMAKE compilation database, and this database only knows about foo.cc files.

    A possible fix/work around might be to also add foo.h in a CMake library, creating a fake one if necessary, for IWYU to "see" these files and do something about it.

    Purely speculative, I never got time to investigate further.

  4. dbarker commented on Sep 16, 2026

    @dbarker
    Member

    Part the of the broader fix should be to complete #1429 and move the SDK implementations to .cc files if header only now.

  5. added
    help wantedGood for taking. Extra help will be provided by maintainers
    triage/acceptedIndicates an issue or PR is ready to be actively worked on.
    and removed
    needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.
    on Sep 16, 2026
  6. github-actions commented on Sep 16, 2026

    @github-actions

    This issue is available for anyone to work on. Make sure to reference this issue in your pull request.
    ✨ Thank you for your contribution! ✨

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

    help wantedGood for taking. Extra help will be provided by maintainerstriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions