WIP: iwyu: Fix warnings in src/test/fuzz and treat them as errors

bitcoin/bitcoin: PR #36808

1 suggestion

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · The new wallet.h IWYU check remains report-only

The new --check_also reports suggestions for test/fuzz/util/wallet.h but does not enforce them, because its only current includer, src/wallet/test/fuzz/spend.cpp, runs in the warnings pass.

Location: ci/test/03_test_script.sh:271 (head).

Details and suggested fix

--check_also reports on the header when IWYU analyzes a translation unit that includes it. The IWYU job's dev-mode configuration includes spend.cpp, but FILES_WITH_ENFORCED_IWYU excludes its wallet/test/fuzz/ path. Its suggestions therefore reach only the warnings pass, which prints the diff without --exit-code. Despite this header living under the newly enforced src/test/fuzz/ tree, its IWYU suggestions cannot fail the job. Include wallet/test/fuzz/spend.cpp in the enforced set once it is IWYU-clean, or document this option as intentionally report-only. No IWYU execution evidence was supplied, so whether the unchanged header produces diagnostics today remains unknown.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

IWYU PR 2142 describes a false forward-declaration requirement produced while analyzing implicit destruction. When an enclosing class destroys a templated member containing a nested type, IWYU scans the instantiated member destructor. Its method-body detection failed to recognize an enclosing destructor, and the nested-type use was attributed to the enclosing class's location—before the nested definition. IWYU consequently suggested an invalid declaration such as struct A::B;, even though B was already defined inside A.

This explains the failure targeted by the two no_forward_declare pragmas: PrivateBroadcast defines CTransactionRefHash and CTransactionRefComp inside the class and uses them as template arguments of its unordered_map member. The suppressions prevent erroneous nested-class declaration suggestions, rather than supplying a missing C++ dependency.

Source 1

The upstream follow-up, PR 2145, identifies traversal of constructor/destructor declaration names as the trigger and proposes skipping that traversal. Its description reports that commit 4966ff6 introduced this particular reproducer's failure, while its parent handled it correctly; it also cautions that the older issue 1707 may have a different original cause.

The cited upstream work provides a specific compatibility boundary to check, not evidence that every IWYU version needs the pragmas. It also distinguishes a proposed upstream fix from proof that Bitcoin Core's configured branch includes that fix.

Source 1

Ralph's inferences

The affected nested-type/container structure predates this PR. Base and head both define the two functors before using them in m_transactions; the head adds suppression annotations without changing that structure.

The workaround addresses tool interpretation of existing valid declarations, not a newly introduced need to forward-declare either functor.

At the pinned head, the reference IWYU workflow builds the upstream clang_23 branch using LLVM 23. Its local patch only changes include quoting and does not repair destructor analysis. Thus no repository-local fix supersedes these pragmas, but the available evidence cannot definitively answer whether the moving upstream branch still requires them.

The supported version is not an older numbered release that can safely be assumed affected or fixed. A definitive yes/no requires establishing the actual clang_23 revision used and whether it contains an effective upstream fix.