Merge bitcoin/bitcoin#35895: refactor: Enable clang-tidy rule to reject anon namespace in header
What changed, and why it matters
This is a code cleanup change that turns on a static-analysis rule to prevent a specific C++ coding pattern (anonymous namespaces in header files) and updates two headers to comply. It does not change how Bitcoin Core behaves at runtime and does not fix an active security bug.
No action required. Treat as normal maintenance/refactor commit.
Security signals we found
No security-relevant code change
No memory safety, cryptography, consensus, or network changes
Tooling-only refactor (clang-tidy configuration)
No bug fix or vulnerability patch present in diff
Evidence from the diff
The merge commit enables the clang-tidy checks fuchsia-header-anon-namespaces and misc-definitions-in-headers in src/.clang-tidy. It suppresses the new check around implementation code in src/bench/nanobench.h and replaces an anonymous-namespace IntIdentity helper with std::identity in src/util/strencodings.h. The change is purely refactor/tooling and is intended to prevent future one-definition-rule (ODR) and compile/link issues, not to patch a known vulnerability.
Changed components
src/.clang-tidysrc/bench/nanobench.hsrc/util/strencodings.hInspect captured patch +9 / −12
### src/.clang-tidy
@@ -8,8 +8,10 @@ bugprone-use-after-move,
bugprone-lambda-function-name,
bugprone-unhandled-self-assignment,
bugprone-unused-return-value,
-misc-unused-using-decls,
+fuchsia-header-anon-namespaces,
+misc-definitions-in-headers,
misc-no-recursion,
+misc-unused-using-decls,
modernize-avoid-bind,
modernize-deprecated-headers,
modernize-use-default-member-init,
### src/bench/nanobench.h
@@ -1369,6 +1369,7 @@ void doNotOptimizeAway(T const& val) {
} // namespace ankerl
#if defined(ANKERL_NANOBENCH_IMPLEMENT)
+// NOLINTBEGIN(misc-definitions-in-headers)
///////////////////////////////////////////////////////////////////////////////////////////////////
// implementation part - only visible in .cpp
@@ -3563,5 +3564,6 @@ std::ostream& operator<<(std::ostream& os, std::vector<ankerl::nanobench::BigO>
} // namespace nanobench
} // namespace ankerl
+// NOLINTEND(misc-definitions-in-headers)
#endif // ANKERL_NANOBENCH_IMPLEMENT
#endif // ANKERL_NANOBENCH_H_INCLUDED
### src/util/strencodings.h
@@ -17,6 +17,7 @@
#include <charconv>
#include <cstddef>
#include <cstdint>
+#include <functional>
#include <limits>
#include <optional>
#include <span>
@@ -214,18 +215,10 @@ bool TimingResistantEqual(const T& a, const T& b)
*/
[[nodiscard]] bool ParseFixedPoint(std::string_view, int decimals, int64_t *amount_out);
-namespace {
-/** Helper class for the default infn argument to ConvertBits (just returns the input). */
-struct IntIdentity
-{
- [[maybe_unused]] int operator()(int x) const { return x; }
-};
-
-} // namespace
-
/** Convert from one power-of-2 number base to another. */
-template<int frombits, int tobits, bool pad, typename O, typename It, typename I = IntIdentity>
-bool ConvertBits(O outfn, It it, It end, I infn = {}) {
+template <int frombits, int tobits, bool pad, typename O, typename It, typename I = std::identity>
+bool ConvertBits(O outfn, It it, It end, I infn = {})
+{
size_t acc = 0;
size_t bits = 0;
constexpr size_t maxv = (1 << tobits) - 1;Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.