Skip to content

[backport] Replace MakeSpan helper with Span deduction guide

This is a backport of https://github.com/bitcoin/bitcoin/pull/23413

C++17 supports user-defined deduction guides, allowing class constructors to be invoked without specifying class template arguments. Instead, the code can contain rules to infer the template arguments from the constructor argument types.

This alleviates the need for the MakeSpan helper. Convert the existing MakeSpan rules into deduction rules for Span itself, and replace all invocations of MakeSpan with just Span ones.

This addresses @cculianu's comment regarding deduction guides replacing MakeSpan.

Clang bug

Note that this change encountered a Clang compiler bug (GCC is not affected), which has been worked around:

image

See https://stackoverflow.com/questions/21387687/c-member-reference-base-type-int-is-not-a-structure-or-union and https://bugs.llvm.org/show_bug.cgi?id=39663. A workaround using MakeUInt8Span has been documented in a comment in netaddress.h !1543 (diffs), and marked as TODO for later cleanup once we're on a version of Clang that doesn't suffer from the bug. This TODO addition is noted in the code quality report:

image

Test plan

ninja check-all

Edited by SlowRiot

Merge request reports