Bitcoin Core 31.99.0
P2P Digital Currency
type-map.h
Go to the documentation of this file.
1// Copyright (c) The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef MP_PROXY_TYPE_MAP_H
6#define MP_PROXY_TYPE_MAP_H
7
8#include <mp/proxy-types.h>
9#include <mp/type-pair.h>
10#include <mp/util.h>
11
12namespace mp {
13template <typename KeyLocalType, typename ValueLocalType, typename Value, typename Output>
14void CustomBuildField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
16 InvokeContext& invoke_context,
17 Value&& value,
18 Output&& output)
19{
20 BuildList(TypeList<std::pair<KeyLocalType, ValueLocalType>>(), invoke_context, output, value);
21}
22
23// Replacement for `m.emplace(piecewise_construct, t1, t2)` to work around a
24// Clang 22 regression triggered by libc++'s std::map piecewise emplace: when
25// the key constructor argument tuple is empty (std::tuple<>), libc++'s internal
26// "try key extraction" SFINAE probe instantiates std::tuple_element<0,
27// std::tuple<>>, which Clang 22 diagnoses as an out-of-bounds pack access ("a
28// parameter pack may not be accessed at an out of bounds index") instead of
29// treating it as substitution failure. See LLVM issue #167709 and the upstream
30// fix in llvm/llvm-project PR #183614.
31// https://github.com/llvm/llvm-project/issues/167709
32// https://github.com/llvm/llvm-project/pull/183614
33template <class Map, class Tuple1, class Tuple2>
35 Map& m,
36 const std::piecewise_construct_t&,
37 Tuple1&& t1,
38 Tuple2&& t2)
39{
40 if constexpr (std::tuple_size_v<std::remove_reference_t<Tuple1>> == 0) {
41 // Avoid tuple<> / tuple<> (LLVM 22 libc++ regression path)
42 return m.emplace(std::piecewise_construct,
43 std::forward_as_tuple(typename Map::key_type{}),
44 std::forward<Tuple2>(t2));
45 } else {
46 return m.emplace(std::piecewise_construct,
47 std::forward<Tuple1>(t1),
48 std::forward<Tuple2>(t2));
49 }
50}
51
52template <typename KeyLocalType, typename ValueLocalType, typename Input, typename ReadDest>
53decltype(auto) CustomReadField(TypeList<std::map<KeyLocalType, ValueLocalType>>,
55 InvokeContext& invoke_context,
56 Input&& input,
57 ReadDest&& read_dest)
58{
59 return ReadList(
60 TypeList<std::pair<const KeyLocalType, ValueLocalType>>(), invoke_context, input, read_dest,
61 [&](auto& value, size_t) { value.clear(); },
62 [&](auto& value, auto&&... args) -> auto& {
63 return *EmplacePiecewiseSafe(value, std::forward<decltype(args)>(args)...).first;
64 });
65}
66} // namespace mp
67
68#endif // MP_PROXY_TYPE_MAP_H
ArgsManager & args
Definition: bitcoind.cpp:280
Functions to serialize / deserialize common bitcoin types.
Definition: common-types.h:57
void BuildList(TypeList< LocalType >, InvokeContext &invoke_context, Output &&output, Value &&value)
Definition: proxy-types.h:284
auto EmplacePiecewiseSafe(Map &m, const std::piecewise_construct_t &, Tuple1 &&t1, Tuple2 &&t2)
Definition: type-map.h:34
decltype(auto) CustomReadField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest)
Overload multiprocess library's CustomReadField hook to allow any object with an Unserialize method t...
Definition: common-types.h:83
decltype(auto) ReadList(TypeList< LocalType >, InvokeContext &invoke_context, Input &&input, ReadDest &&read_dest, InitFn &&init, EmplaceFn &&emplace)
Definition: proxy-types.h:295
void CustomBuildField(TypeList< LocalType >, Priority< 1 >, InvokeContext &invoke_context, Value &&value, Output &&output)
Overload multiprocess library's CustomBuildField hook to allow any serializable object to be stored i...
Definition: common-types.h:63
Function parameter type for prioritizing overloaded function calls that would otherwise be ambiguous.
Definition: util.h:115
Generic utility functions used by capnp code.
Definition: util.h:39