diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-03-15 11:14:59 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-03-20 19:18:53 +0100 |
commit | 074d3d54d8f67599402f3d175ce0368ef4f13269 (patch) | |
tree | a2730956e0f2d65a6b89f67b3a46b6ef32c982ff /examples/corelib | |
parent | db5279825cd0f2e87e59a540844059bc5d30ce94 (diff) | |
download | qtbase-074d3d54d8f67599402f3d175ce0368ef4f13269.tar.gz |
Use local names to make some numeric_limits references more readable
Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I220f5c2f13c8f01278be806c8e8d6a3a1be8e986
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples/corelib')
-rw-r--r-- | examples/corelib/serialization/cbordump/main.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/corelib/serialization/cbordump/main.cpp b/examples/corelib/serialization/cbordump/main.cpp index ed079d6a97..a53bbdebda 100644 --- a/examples/corelib/serialization/cbordump/main.cpp +++ b/examples/corelib/serialization/cbordump/main.cpp @@ -181,18 +181,19 @@ QCborError CborDumper::dump() template <typename T> static inline bool canConvertTo(double v) { + using TypeInfo = std::numeric_limits<T>; // The [conv.fpint] (7.10 Floating-integral conversions) section of the // standard says only exact conversions are guaranteed. Converting // integrals to floating-point with loss of precision has implementation- // defined behavior whether the next higher or next lower is returned; // converting FP to integral is UB if it can't be represented.; - static_assert(std::numeric_limits<T>::is_integer); + static_assert(TypeInfo::is_integer); - double supremum = ldexp(1, std::numeric_limits<T>::digits); + double supremum = ldexp(1, TypeInfo::digits); if (v >= supremum) return false; - if (v < std::numeric_limits<T>::min()) // either zero or a power of two, so it's exact + if (v < TypeInfo::min()) // either zero or a power of two, so it's exact return false; // we're in range @@ -428,6 +429,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel) }; auto printString = [=](const char *descr) { + constexpr qsizetype ChunkSizeLimit = std::numeric_limits<int>::max(); QByteArray indent(nestingLevel * 2, ' '); const char *chunkStr = (reader.isLengthKnown() ? "" : "chunk "); int width = 48 - indent.size(); @@ -436,7 +438,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel) qsizetype size = reader.currentStringChunkSize(); if (size < 0) return; // error - if (size >= std::numeric_limits<int>::max()) { + if (size >= ChunkSizeLimit) { fprintf(stderr, "String length too big, %lli\n", qint64(size)); exit(EXIT_FAILURE); } @@ -493,7 +495,7 @@ void CborDumper::dumpOneDetailed(int nestingLevel) size = reader.currentStringChunkSize(); if (size < 0) return; // error - if (size >= std::numeric_limits<int>::max()) { + if (size >= ChunkSizeLimit) { fprintf(stderr, "String length too big, %lli\n", qint64(size)); exit(EXIT_FAILURE); } |