ci: check headers with include-what-you-use - #77
ci: check headers with include-what-you-use#77devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Andrew He <he.andrew.mail@gmail.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| #include <utility> | ||
| #include <array> | ||
| #include <tuple> | ||
| #include <cstdlib> |
There was a problem hiding this comment.
🟡 Two library headers still fail to compile on their own because a needed standard header is missing
The include list is rewritten and sorted (#include <cstdlib> at src/quaternion_hurwitz.hpp:4) without adding the standard header that supplies assert, so anyone including this header on its own gets a compile failure the moment the checking code runs.
Impact: Users who include these headers first (without a catch-all include) hit build errors instead of a working library.
Why the new include audit misses the missing
src/quaternion_hurwitz.hpp:18 uses assert(...) inside a constructor template, and src/tensor.hpp:30 and src/tensor.hpp:57 use assert(...) inside member templates, but neither header includes <cassert> (see the rewritten include blocks at src/quaternion_hurwitz.hpp:3-7 and src/tensor.hpp:3-6).
The new iwyu job compiles a stub that only includes the header, so these templates are never instantiated and the undeclared assert is never diagnosed; the check therefore passes while the headers remain non-self-contained. Both files are touched by this PR's include cleanup, so <cassert> should be added.
| #include <cstdlib> | |
| #include <cassert> | |
| #include <cstdlib> |
Was this helpful? React with 👍 or 👎 to provide feedback.
| @@ -1,6 +1,7 @@ | |||
| #include <cassert> | |||
| #include <array> | |||
| #include <cassert> | |||
There was a problem hiding this comment.
🟡 One library header has no protection against being included twice
The header's top-of-file include list is rewritten (#include <cassert> at src/seg_tree.hpp:2) while the file still starts without the one-time-inclusion marker every other header has, so including it twice in one program breaks the build with duplicate definitions.
Impact: Any program that pulls this header in through two different paths fails to compile.
Missing #pragma once
Every other library header begins with #pragma once (e.g. src/bit.hpp:1, src/tensor.hpp:1), but src/seg_tree.hpp starts directly with its includes, so a second inclusion re-defines seg_tree::floor_log_2, seg_tree::point, seg_tree::range, etc.
This is pre-existing, but the PR edits exactly these first lines as part of the header-hygiene pass, and the new iwyu stub (one include per TU) cannot detect it.
Prompt for agents
src/seg_tree.hpp lacks the `#pragma once` include guard that all other headers in src/ start with, so including it twice in a translation unit produces redefinition errors for everything in namespace seg_tree. Add `#pragma once` followed by a blank line before the include block, matching the convention in the rest of src/.
Was this helpful? React with 👍 or 👎 to provide feedback.
GCC Code Coverage Report📂 Overall coverage
|
Summary
Adds an
iwyuCI job that runs include-what-you-use (Ubuntu 26.04'siwyupackage, clang 19-based) over everysrc/library header, and fixes all its findings so the check starts green.The job mirrors the coverage-stub approach: one stub TU per header (
#include "x.hpp" // IWYU pragma: keep) compiled with-std=c++23 -I src, checked with-Xiwyu --check_also=src/x.hpp -Xiwyu --error=1, fanned out withxargs -P. Suggestions surface as::error file=src/x.hppannotations plus the full iwyu report..iwyu.impmaps away libstdc++ false positives so only real issues fail:<c*>spellings (assert→<cassert>,size_t→<cstddef>,intN_t→<cstdint>, ...);std::vector/std::pair/std::swap/std::size, which libstdc++ 15 re-exports from unrelated headers (iwyu otherwise suggests<format> // for vector);<exception>treated as provided by<utility>(libstdc++'sstd::swap(exception_ptr&, ...)overload otherwise makes iwyu demand<exception>for anystd::swapcall).Header fixes (mostly
fix_include-applied, then hand-tidied):bm.hpp,geometry/point3d.hpp,hash_map.hpp,mcmf.hpp: replace<bits/stdc++.h>with the specific standard headers.fft/all.hpp: wrapped inIWYU pragma: begin_exports/end_exportsand switched to"fft/..."include paths like the other fft headers.<utility>forstd::swap,<functional>forstd::lessdefaults,"fft/common.hpp"/"fft/engine.hpp"where used directly), drop a few unused ones (<cassert>inmanacher.hpp,"fft/common.hpp"infft/engine.hpp, a redundant fwd-decl indirichlet_series.hpp), and sort include lists.Verified locally in an ubuntu:26.04 container (iwyu clean on all 50 headers), plus
cmake --build && ctest(102/102 pass),scripts/bundle.py --all --check, and-fsyntax-onlycompiles of allverify/solutions with g++-15.Link to Devin session: https://app.devin.ai/sessions/fe0dc8e65b874385b5ad5387cec1e595
Requested by: @ecnerwala