bitcoin/src/util/byte_units.h
Vasil Dimov d3339a7cd5
util: fix compiler warning about deprecated space before _MiB
```
src/util/byte_units.h:13:29: error: identifier '_MiB' preceded by whitespace in a literal operator declaration is deprecated [-Werror,-Wdeprecated-literal-operator]
   13 | constexpr size_t operator"" _MiB(unsigned long long mebibytes)
      |                  ~~~~~~~~~~~^~~~
      |                  operator""_MiB
1 error generated.
```

Clang 20.0.0
2025-01-20 14:32:20 +01:00

23 lines
690 B
C++

// Copyright (c) 2025-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_UTIL_BYTE_UNITS_H
#define BITCOIN_UTIL_BYTE_UNITS_H
#include <util/overflow.h>
#include <stdexcept>
//! Overflow-safe conversion of MiB to bytes.
constexpr size_t operator""_MiB(unsigned long long mebibytes)
{
auto bytes{CheckedLeftShift(mebibytes, 20)};
if (!bytes || *bytes > std::numeric_limits<size_t>::max()) {
throw std::overflow_error("MiB value too large for size_t byte conversion");
}
return *bytes;
}
#endif // BITCOIN_UTIL_BYTE_UNITS_H