From 817a3712208cad51e841680a9ae92a35563d79f6 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 30 Nov 2019 16:11:12 +0100 Subject: [PATCH] Removed rangechecked_cast was not working as I hoped. --- core/BackupFormatModel.cpp | 7 ++--- core/ExplainTreeModelItem.cpp | 3 +- core/core.pro | 1 - core/rangechecked_cast.h | 15 ---------- tests/pglabtests/pglabtests.pro | 1 - tests/pglabtests/tst_rangechecked_cast.cpp | 35 ---------------------- 6 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 core/rangechecked_cast.h delete mode 100644 tests/pglabtests/tst_rangechecked_cast.cpp diff --git a/core/BackupFormatModel.cpp b/core/BackupFormatModel.cpp index 4ea073c..c7d23e8 100644 --- a/core/BackupFormatModel.cpp +++ b/core/BackupFormatModel.cpp @@ -1,5 +1,4 @@ #include "BackupFormatModel.h" -#include "rangechecked_cast.h" #include namespace { @@ -61,7 +60,7 @@ BackupFormatModel::BackupFormatModel(QObject *parent) int BackupFormatModel::rowCount(const QModelIndex &) const { - int size = rangechecked_cast(g_BackupFormats.size()); + int size = static_cast(g_BackupFormats.size()); return size; } @@ -79,7 +78,7 @@ QVariant BackupFormatModel::data(const QModelIndex &index, int role) const const int col = index.column(); if (role == Qt::DisplayRole) { - const auto &item = g_BackupFormats.at(rangechecked_cast(row)); + const auto &item = g_BackupFormats.at(static_cast(row)); switch (col) { case ColumnShort: result = item.shortFlag; @@ -93,7 +92,7 @@ QVariant BackupFormatModel::data(const QModelIndex &index, int role) const } } else if (role == Qt::ToolTipRole) { - const auto &item = g_BackupFormats.at(rangechecked_cast(row)); + const auto &item = g_BackupFormats.at(static_cast(row)); result = item.description; } } diff --git a/core/ExplainTreeModelItem.cpp b/core/ExplainTreeModelItem.cpp index ef5344b..115eacb 100644 --- a/core/ExplainTreeModelItem.cpp +++ b/core/ExplainTreeModelItem.cpp @@ -1,6 +1,5 @@ #include "ExplainTreeModelItem.h" #include "json/json.h" -#include "rangechecked_cast.h" #include namespace { @@ -111,7 +110,7 @@ ExplainTreeModelItemPtr ExplainTreeModelItem::child(int row) int ExplainTreeModelItem::childCount() const { - return rangechecked_cast(m_childItems.size()); + return static_cast(m_childItems.size()); } //int ExplainTreeModelItem::columnCount() const diff --git a/core/core.pro b/core/core.pro index fa842c8..ab3d990 100644 --- a/core/core.pro +++ b/core/core.pro @@ -56,7 +56,6 @@ HEADERS += PasswordManager.h \ SqlAstSelectListEntry.h \ SqlAstSelect.h \ SqlAstExpression.h \ - rangechecked_cast.h \ std_utils.h \ IntegerRange.h diff --git a/core/rangechecked_cast.h b/core/rangechecked_cast.h deleted file mode 100644 index 825e535..0000000 --- a/core/rangechecked_cast.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef RANGECHECKED_CAST_H -#define RANGECHECKED_CAST_H - -#include -#include - -template -To rangechecked_cast(From f) -{ -// BOOST_ASSERT(f >= std::numeric_limits::lowest()); -// BOOST_ASSERT(f <= std::numeric_limits::max()); - return static_cast(f); -} - -#endif // RANGECHECKED_CAST_H diff --git a/tests/pglabtests/pglabtests.pro b/tests/pglabtests/pglabtests.pro index d58e4b8..73c4847 100644 --- a/tests/pglabtests/pglabtests.pro +++ b/tests/pglabtests/pglabtests.pro @@ -20,7 +20,6 @@ SOURCES += main.cpp \ tst_escapeConnectionStringValue.cpp \ tst_expected.cpp \ tst_SqlLexer.cpp \ - tst_rangechecked_cast.cpp \ tst_scopeguard.cpp \ tst_CsvWriter.cpp \ tst_PasswordManager.cpp \ diff --git a/tests/pglabtests/tst_rangechecked_cast.cpp b/tests/pglabtests/tst_rangechecked_cast.cpp deleted file mode 100644 index 7ea2460..0000000 --- a/tests/pglabtests/tst_rangechecked_cast.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include "rangechecked_cast.h" -#include "PrintTo_Qt.h" - -using namespace testing; - - -TEST(rangechecked_cast, in_range) -{ - ASSERT_NO_THROW({ - int8_t in = 42; - int expected = 42; - auto output = rangechecked_cast(in); - ASSERT_EQ(output, expected); - }); -} - -TEST(rangechecked_cast, above_max) -{ - int64_t in = std::numeric_limits::max() + static_cast(1); - ASSERT_THROW({ - rangechecked_cast(in); - }, - std::runtime_error); -} - -TEST(rangechecked_cast, below_lowest) -{ - int64_t in = std::numeric_limits::lowest() - static_cast(1); - ASSERT_THROW({ - rangechecked_cast(in); - }, - std::runtime_error); -}