From bf22f56d74903e35edec68e8411b898a9f815783 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 1 Feb 2020 10:18:48 +0100 Subject: [PATCH] order static and constexpr consistently --- docs/gen_reference_doc.py | 8 ++++++++ include/libtorrent/aux_/block_cache_reference.hpp | 2 +- include/libtorrent/bandwidth_queue_entry.hpp | 2 +- include/libtorrent/kademlia/types.hpp | 6 +++--- include/libtorrent/packet_pool.hpp | 4 ++-- include/libtorrent/piece_block_progress.hpp | 2 +- include/libtorrent/session_handle.hpp | 4 ++-- include/libtorrent/sha1_hash.hpp | 2 +- include/libtorrent/torrent.hpp | 2 +- 9 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/gen_reference_doc.py b/docs/gen_reference_doc.py index c33cd87f4..5692e0d0a 100644 --- a/docs/gen_reference_doc.py +++ b/docs/gen_reference_doc.py @@ -497,6 +497,10 @@ def parse_class(lno, lines, filename): continue if looks_like_variable(line): + if 'constexpr static' in line: + print('ERROR: found "constexpr static", use "static constexpr" instead for consistency!\n%s:%d\n%s' + % (filename, lno, line)) + sys.exit(1) if verbose: print('var %s' % line) if not is_visible(context): @@ -840,6 +844,10 @@ for filename in files: continue if looks_like_constant(line): + if 'constexpr static' in line: + print('ERROR: found "constexpr static", use "static constexpr" instead for consistency!\n%s:%d\n%s' + % (filename, lno, line)) + sys.exit(1) current_constant, lno = parse_constant(lno - 1, lines, filename) if current_constant is not None and is_visible(context): if 'TODO: ' in context: diff --git a/include/libtorrent/aux_/block_cache_reference.hpp b/include/libtorrent/aux_/block_cache_reference.hpp index 089b03eb1..36c80c399 100644 --- a/include/libtorrent/aux_/block_cache_reference.hpp +++ b/include/libtorrent/aux_/block_cache_reference.hpp @@ -46,7 +46,7 @@ namespace libtorrent { namespace aux { // if the cookie is set to this value, it doesn't refer to anything in the // cache (and the buffer is mutable) - constexpr static std::int32_t none = 0x7fffffff; + static constexpr std::int32_t none = 0x7fffffff; storage_index_t storage{0}; std::int32_t cookie = none; diff --git a/include/libtorrent/bandwidth_queue_entry.hpp b/include/libtorrent/bandwidth_queue_entry.hpp index 5db1dbd6b..828b54c99 100644 --- a/include/libtorrent/bandwidth_queue_entry.hpp +++ b/include/libtorrent/bandwidth_queue_entry.hpp @@ -64,7 +64,7 @@ struct TORRENT_EXTRA_EXPORT bw_request // from the most limiting one int assign_bandwidth(); - constexpr static int max_bandwidth_channels = 10; + static constexpr int max_bandwidth_channels = 10; // we don't actually support more than 10 channels per peer aux::array channel{}; }; diff --git a/include/libtorrent/kademlia/types.hpp b/include/libtorrent/kademlia/types.hpp index 473a17ed5..23c0c87cd 100644 --- a/include/libtorrent/kademlia/types.hpp +++ b/include/libtorrent/kademlia/types.hpp @@ -46,7 +46,7 @@ namespace libtorrent { namespace dht { { std::copy(b, b + len, bytes.begin()); } bool operator==(public_key const& rhs) const { return bytes == rhs.bytes; } - constexpr static int len = 32; + static constexpr int len = 32; std::array bytes; }; @@ -57,7 +57,7 @@ namespace libtorrent { namespace dht { { std::copy(b, b + len, bytes.begin()); } bool operator==(secret_key const& rhs) const { return bytes == rhs.bytes; } - constexpr static int len = 64; + static constexpr int len = 64; std::array bytes; }; @@ -68,7 +68,7 @@ namespace libtorrent { namespace dht { { std::copy(b, b + len, bytes.begin()); } bool operator==(signature const& rhs) const { return bytes == rhs.bytes; } - constexpr static int len = 64; + static constexpr int len = 64; std::array bytes; }; diff --git a/include/libtorrent/packet_pool.hpp b/include/libtorrent/packet_pool.hpp index 9a486f57f..92086c19a 100644 --- a/include/libtorrent/packet_pool.hpp +++ b/include/libtorrent/packet_pool.hpp @@ -210,8 +210,8 @@ namespace libtorrent { else if (allocate <= m_mtu_ceiling_slab.allocate_size) { return m_mtu_ceiling_slab.alloc(); } return create_packet(allocate); } - constexpr static int mtu_floor_size = TORRENT_INET_MIN_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER; - constexpr static int mtu_ceiling_size = TORRENT_ETHERNET_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER; + static constexpr int mtu_floor_size = TORRENT_INET_MIN_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER; + static constexpr int mtu_ceiling_size = TORRENT_ETHERNET_MTU - TORRENT_IPV4_HEADER - TORRENT_UDP_HEADER; packet_slab m_syn_slab; packet_slab m_mtu_floor_slab; packet_slab m_mtu_ceiling_slab; diff --git a/include/libtorrent/piece_block_progress.hpp b/include/libtorrent/piece_block_progress.hpp index 71bbb2471..b0ec037cf 100644 --- a/include/libtorrent/piece_block_progress.hpp +++ b/include/libtorrent/piece_block_progress.hpp @@ -40,7 +40,7 @@ namespace libtorrent { struct piece_block_progress { - constexpr static piece_index_t invalid_index{-1}; + static constexpr piece_index_t invalid_index{-1}; // the piece and block index // determines exactly which diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index 730ad9beb..131cb898a 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -1058,8 +1058,8 @@ namespace libtorrent { #endif // protocols used by add_port_mapping() - constexpr static portmap_protocol udp = portmap_protocol::udp; - constexpr static portmap_protocol tcp = portmap_protocol::tcp; + static constexpr portmap_protocol udp = portmap_protocol::udp; + static constexpr portmap_protocol tcp = portmap_protocol::tcp; // add_port_mapping adds one or more port forwards on UPnP and/or NAT-PMP, // whichever is enabled. A mapping is created for each listen socket diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index 9c6f320bf..61a6fe55d 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -73,7 +73,7 @@ namespace aux { { static_assert(N % 32 == 0, "N must be a multiple of 32"); static constexpr std::ptrdiff_t number_size = N / 32; - constexpr static int bits_in_byte = 8; + static constexpr int bits_in_byte = 8; public: using difference_type = std::ptrdiff_t; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 70f56dbf9..f78cc54c1 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -624,7 +624,7 @@ namespace libtorrent { // -------------------------------------------- // PEER MANAGEMENT - constexpr static web_seed_flag_t ephemeral = 0_bit; + static constexpr web_seed_flag_t ephemeral = 0_bit; // add_web_seed won't add duplicates. If we have already added an entry // with this URL, we'll get back the existing entry