Skip to content

Conversation

@eramongodb
Copy link
Contributor

@eramongodb eramongodb commented Oct 28, 2025

To improve the quality of clangd's IWYU diagnostics, this PR applies the IWYU "export" macro to deliberate transitive includes.

Include directives which are "exported" are:

  • publically documented transitive includes (with \par Includes), or
  • include of a direct component header (forward, declaration, internal, or test).

All clangd IWYU warnings in v1 components (or required by v1 components) are addressed. Reordering or removal of includes in v_noabi public headers are skipped to avoid unnecessary potential for breaking changes.

Even with these changes, the IWYU tool still emits noise, e.g. <bsoncxx/private/bson.hh> exports <bson/bson.h>, but some components still emit the following warnings:

No header providing "bson_t" is directly included (fix available) [clangd(missing-includes)]
No header providing "bson_malloc" is directly included (fix available) [clangd(missing-includes)]
No header providing "BSON_VERSION_S" is directly included (fix available) [clangd(missing-includes)]
...

despite other entities provided by <bson/bson.h> being (correctly) handled by the export. The <bson/bson.h> might need to be annotated with similar comments for these warnings to go away. Similarly, <type_traits> does not seem to be identified via <bsoncxx/private/type_traits.hh> -> <bsoncxx/v1/detail/type_traits.hpp> -> <type_traits> either. (Possibly related: include-what-you-use/include-what-you-use#1645)

Update: confirmed these are due to the lack of IWYU export pragmas in <bson/bson.h>: mongodb/mongo-c-driver#2167.

Fixing warnings for missing IWYU of third party library headers (e.g. Catch2 and <catch2/catch_message.hpp>) are skipped by this PR. Unsure if there is a nice way to silence these warnings for headers we do not own. The following can be added to the clangd configuration file (either per-project or global):

Diagnostics:
  Includes:
    IgnoreHeader: .*/_deps/.*

@eramongodb eramongodb self-assigned this Oct 28, 2025
@eramongodb eramongodb requested a review from a team as a code owner October 28, 2025 17:10
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

Successfully merging this pull request may close these issues.

1 participant