Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/encoder/encoder.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ SOURCES += tst_encoder.cpp
CONFIG += testcase parallel_test c++11
QT = core testlib

DEFINES += QT_NO_FOREACH QT_NO_AS_CONST

INCLUDEPATH += ../../src
msvc: POST_TARGETDEPS = ../../lib/tinycbor.lib
else: POST_TARGETDEPS += ../../lib/libtinycbor.a
Expand Down
15 changes: 14 additions & 1 deletion tests/encoder/tst_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
#include <qfloat16.h>
#endif

#include <utility>
namespace t17 {
#ifdef __cpp_lib_as_const
using std::as_const;
#else
template <typename T>
constexpr typename std::add_const<T>::type &as_const(T &t) noexcept { return t; }
// prevent rvalue arguments:
template <typename T>
void as_const(const T &&) = delete;
#endif // __cpp_lib_as_const
} // namespace t17

Q_DECLARE_METATYPE(CborError)
namespace QTest {
template<> char *toString<CborError>(const CborError &err)
Expand Down Expand Up @@ -153,7 +166,7 @@ CborError encodeVariant(CborEncoder *encoder, const QVariant &v)
CborError err = cbor_encoder_create_array(encoder, &sub, len);
if (err && !isOomError(err))
return err;
foreach (const QVariant &v2, list) {
for (const QVariant &v2 : t17::as_const(list)) {
err = static_cast<CborError>(err | encodeVariant(&sub, v2));
if (err && !isOomError(err))
return err;
Expand Down