summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-08-29 15:12:57 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-08-29 15:12:57 +0100
commit6c7222e071ffe7d20c138faac0da1d708e0a7779 (patch)
tree86ad5d55f60b42b648fbdfc4183e160aacd5ef6c
parentAdd -Wuseless-cast (diff)
downloadmygrate-6c7222e071ffe7d20c138faac0da1d708e0a7779.tar.bz2
mygrate-6c7222e071ffe7d20c138faac0da1d708e0a7779.tar.xz
mygrate-6c7222e071ffe7d20c138faac0da1d708e0a7779.zip
Add -Wold-style-cast
-rw-r--r--Jamroot.jam1
-rw-r--r--lib/compileTimeFormatter.h2
-rw-r--r--lib/input/mysqlBindings.cpp3
-rw-r--r--lib/output/pq/pqConn.cpp7
-rw-r--r--lib/output/pq/pqRecordSet.cpp8
-rw-r--r--lib/output/pq/pqStmt.cpp6
-rw-r--r--lib/output/pq/writePqCopyStrm.cpp2
-rw-r--r--lib/row.cpp3
-rw-r--r--lib/streamSupport.cpp3
-rw-r--r--test/test-e2e.cpp16
-rw-r--r--test/test-misc.cpp24
-rw-r--r--test/testdb-mysql.cpp3
12 files changed, 41 insertions, 37 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index c32fb4a..edceeb1 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -21,6 +21,7 @@ project : requirements
<variant>debug:<warnings>extra
<variant>debug:<warnings-as-errors>on
<variant>debug:<cflags>-Wnon-virtual-dtor
+ <variant>debug:<cflags>-Wold-style-cast
<variant>debug:<cflags>-Wcast-align
<variant>debug:<cflags>-Wunused
<variant>debug:<cflags>-Woverloaded-virtual
diff --git a/lib/compileTimeFormatter.h b/lib/compileTimeFormatter.h
index 647fb30..7d69d4b 100644
--- a/lib/compileTimeFormatter.h
+++ b/lib/compileTimeFormatter.h
@@ -344,7 +344,7 @@ namespace MyGrate {
static inline void
write(stream & s, Obj * const ptr, const Pn &... pn)
{
- s << std::showbase << std::hex << (long unsigned int)ptr;
+ s << std::showbase << std::hex << static_cast<long unsigned int>(ptr);
s.copyfmt(std::ios(nullptr));
StreamWriter::next(s, pn...);
}
diff --git a/lib/input/mysqlBindings.cpp b/lib/input/mysqlBindings.cpp
index 3895821..089ced5 100644
--- a/lib/input/mysqlBindings.cpp
+++ b/lib/input/mysqlBindings.cpp
@@ -22,7 +22,6 @@ namespace MyGrate::Input {
MYSQL_TIME &
operator<<(MYSQL_TIME & t, const DateTime & dt)
{
- return t << (Date)dt << (Time)dt;
+ return t << static_cast<Date>(dt) << static_cast<Time>(dt);
}
-
}
diff --git a/lib/output/pq/pqConn.cpp b/lib/output/pq/pqConn.cpp
index 983271e..6d89fb7 100644
--- a/lib/output/pq/pqConn.cpp
+++ b/lib/output/pq/pqConn.cpp
@@ -34,7 +34,8 @@ namespace MyGrate::Output::Pq {
PqConn::query(const char * const q, const std::initializer_list<DbValue> & vs)
{
Bindings b {vs};
- ResPtr res {PQexecParams(conn.get(), q, (int)vs.size(), nullptr, b.values.data(), b.lengths.data(), nullptr, 0),
+ ResPtr res {PQexecParams(conn.get(), q, static_cast<int>(vs.size()), nullptr, b.values.data(), b.lengths.data(),
+ nullptr, 0),
&PQclear};
verify<PqErr>(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q, res.get());
}
@@ -72,8 +73,8 @@ namespace MyGrate::Output::Pq {
{nullptr,
[](void * cookie, const char * buf, size_t size) {
auto conn = static_cast<PqConn *>(cookie)->conn.get();
- verify<PqErr>(PQputCopyData(conn, buf, (int)size) == 1, "copy data", conn);
- return (ssize_t)size;
+ verify<PqErr>(PQputCopyData(conn, buf, static_cast<int>(size)) == 1, "copy data", conn);
+ return static_cast<ssize_t>(size);
},
nullptr,
[](void * cookie) {
diff --git a/lib/output/pq/pqRecordSet.cpp b/lib/output/pq/pqRecordSet.cpp
index 4d5349f..9eeb3cd 100644
--- a/lib/output/pq/pqRecordSet.cpp
+++ b/lib/output/pq/pqRecordSet.cpp
@@ -30,12 +30,12 @@ namespace MyGrate::Output::Pq {
DbValue
PqRecordSet::at(std::size_t row, std::size_t col) const
{
- if (PQgetisnull(res.get(), (int)row, (int)col)) {
+ if (PQgetisnull(res.get(), static_cast<int>(row), static_cast<int>(col))) {
return nullptr;
}
- const auto value {PQgetvalue(res.get(), (int)row, (int)col)};
- const auto size {static_cast<size_t>(PQgetlength(res.get(), (int)row, (int)col))};
- const auto type {PQftype(res.get(), (int)col)};
+ const auto value {PQgetvalue(res.get(), static_cast<int>(row), static_cast<int>(col))};
+ const auto size {static_cast<size_t>(PQgetlength(res.get(), static_cast<int>(row), static_cast<int>(col)))};
+ const auto type {PQftype(res.get(), static_cast<int>(col))};
switch (type) {
// case BITOID: TODO bool
// case BOOLOID: TODO bool
diff --git a/lib/output/pq/pqStmt.cpp b/lib/output/pq/pqStmt.cpp
index c6399e4..bb7a79c 100644
--- a/lib/output/pq/pqStmt.cpp
+++ b/lib/output/pq/pqStmt.cpp
@@ -22,8 +22,8 @@ namespace MyGrate::Output::Pq {
PqPrepStmt::execute(const std::span<const DbValue> vs)
{
Bindings b {vs};
- res = {PQexecPrepared(
- conn, name.c_str(), (int)vs.size(), b.values.data(), b.lengths.data(), b.formats.data(), 0),
+ res = {PQexecPrepared(conn, name.c_str(), static_cast<int>(vs.size()), b.values.data(), b.lengths.data(),
+ b.formats.data(), 0),
&PQclear};
verify<PqErr>(PQresultStatus(res.get()) == PGRES_COMMAND_OK || PQresultStatus(res.get()) == PGRES_TUPLES_OK,
name, conn);
@@ -54,7 +54,7 @@ namespace MyGrate::Output::Pq {
return i->second;
}
auto nam {scprintf<"pst%0lx">(c->stmts.size())};
- ResPtr res {PQprepare(c->conn.get(), nam.c_str(), q, (int)n, nullptr), PQclear};
+ ResPtr res {PQprepare(c->conn.get(), nam.c_str(), q, static_cast<int>(n), nullptr), PQclear};
verify<PqErr>(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q, c->conn.get());
return c->stmts.emplace(q, std::move(nam)).first->second;
}
diff --git a/lib/output/pq/writePqCopyStrm.cpp b/lib/output/pq/writePqCopyStrm.cpp
index 984b4fd..9d52a46 100644
--- a/lib/output/pq/writePqCopyStrm.cpp
+++ b/lib/output/pq/writePqCopyStrm.cpp
@@ -84,7 +84,7 @@ namespace MyGrate::Output::Pq {
}()};
fputs("\\\\x", out);
std::for_each(v.begin(), v.end(), [this](auto b) {
- fwrite(hex[(uint8_t)b].data(), 2, 1, out);
+ fwrite(hex[static_cast<uint8_t>(b)].data(), 2, 1, out);
});
}
}
diff --git a/lib/row.cpp b/lib/row.cpp
index ba8045d..54e2728 100644
--- a/lib/row.cpp
+++ b/lib/row.cpp
@@ -21,7 +21,8 @@ namespace MyGrate {
auto colIter {columnFlags.begin()};
for (auto c {0U}; c < tm.column_count; c++) {
if (*colIter) {
- const enum_field_types type {(enum_field_types)(unsigned char)tm.column_types.str[c]};
+ const enum_field_types type {
+ static_cast<enum_field_types>(static_cast<unsigned char>(tm.column_types.str[c]))};
const auto null {*nullIter};
if (null) {
switch (type) {
diff --git a/lib/streamSupport.cpp b/lib/streamSupport.cpp
index 433fb83..f80f2fa 100644
--- a/lib/streamSupport.cpp
+++ b/lib/streamSupport.cpp
@@ -49,7 +49,8 @@ namespace std {
std::ostream &
operator<<(std::ostream & s, const MyGrate::DateTime & dt)
{
- return MyGrate::scprintf<"%? %?">(s, (const MyGrate::Date)dt, (const MyGrate::Time)dt);
+ return MyGrate::scprintf<"%? %?">(
+ s, static_cast<const MyGrate::Date>(dt), static_cast<const MyGrate::Time>(dt));
}
std::ostream &
diff --git a/test/test-e2e.cpp b/test/test-e2e.cpp
index 768f7c9..8d9afb9 100644
--- a/test/test-e2e.cpp
+++ b/test/test-e2e.cpp
@@ -227,38 +227,38 @@ TEST_TYPE(MYSQL_TYPE_ENUM, std::string_view, std::string_view, enum('alpha', 'be
}
TEST_TYPE(MYSQL_TYPE_TINY, int8_t, int8_t, tinyint)
{
- return (int8_t)n;
+ return static_cast<int8_t>(n);
}
TEST_TYPE(MYSQL_TYPE_SHORT, int16_t, int16_t, smallint)
{
- return (int16_t)n;
+ return static_cast<int16_t>(n);
}
TEST_TYPE(MYSQL_TYPE_INT24, int32_t, int32_t, int)
{
- return (int32_t)n;
+ return static_cast<int32_t>(n);
}
TEST_TYPE(MYSQL_TYPE_YEAR, int16_t, int16_t, year)
{
if (!n) {
return 0;
}
- return (int16_t)n + 1901;
+ return static_cast<int16_t>(n + 1901);
}
TEST_TYPE(MYSQL_TYPE_LONG, int32_t, int32_t, int)
{
- return (int32_t)n;
+ return static_cast<int32_t>(n);
}
TEST_TYPE(MYSQL_TYPE_LONGLONG, int64_t, int64_t, bigint)
{
- return (int64_t)n;
+ return static_cast<int64_t>(n);
}
TEST_TYPE(MYSQL_TYPE_FLOAT, float, float, float)
{
- return (float)n;
+ return static_cast<float>(n);
}
TEST_TYPE(MYSQL_TYPE_DOUBLE, double, double, real)
{
- return (double)n;
+ return static_cast<double>(n);
}
static struct tm
test_tm(size_t n)
diff --git a/test/test-misc.cpp b/test/test-misc.cpp
index aef2694..b4eeb41 100644
--- a/test/test-misc.cpp
+++ b/test/test-misc.cpp
@@ -71,8 +71,8 @@ BOOST_AUTO_TEST_CASE(DbValueConvStrViewToStringView)
{
using namespace std::literals;
MyGrate::DbValue v {"str"};
- BOOST_CHECK_EQUAL((std::string_view)v, "str"sv);
- BOOST_CHECK_EQUAL((std::string)v, "str"s);
+ BOOST_CHECK_EQUAL(static_cast<std::string_view>(v), "str"sv);
+ BOOST_CHECK_EQUAL(static_cast<std::string>(v), "str"s);
}
static_assert(MyGrate::detail::HasToString<int>);
@@ -82,14 +82,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvIntToString, I, Ints)
{
using namespace std::literals;
MyGrate::DbValue v {I {123}};
- BOOST_CHECK_EQUAL((std::string)v, "123"s);
+ BOOST_CHECK_EQUAL(static_cast<std::string>(v), "123"s);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvFloatToString, F, Floats)
{
using namespace std::literals;
MyGrate::DbValue v {F {123}};
- BOOST_CHECK_EQUAL((std::string)v, "123.000000"s);
+ BOOST_CHECK_EQUAL(static_cast<std::string>(v), "123.000000"s);
}
BOOST_AUTO_TEST_CASE(create_datetime)
@@ -106,14 +106,14 @@ BOOST_AUTO_TEST_CASE(create_datetime)
BOOST_AUTO_TEST_CASE(mod100_extract)
{
long unsigned int i {1629222289};
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 89);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 22);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 22);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 29);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 16);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 0);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 0);
- BOOST_CHECK_EQUAL((int)MyGrate::mod100_extract(i), 0);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 89);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 22);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 22);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 29);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 16);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0);
+ BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0);
}
using ConvertTimeData = std::tuple<uint32_t, MyGrate::Time>;
diff --git a/test/testdb-mysql.cpp b/test/testdb-mysql.cpp
index 24e41c0..a2c8885 100644
--- a/test/testdb-mysql.cpp
+++ b/test/testdb-mysql.cpp
@@ -8,7 +8,8 @@ namespace MyGrate::Testing {
const char * const MySQLDB::SERVER {MyGrate::getenv("MYGRATE_MYSQL_SERVER", "localhost")};
const char * const MySQLDB::USER {MyGrate::getenv("MYGRATE_MYSQL_USER", ::getenv("LOGNAME"))};
const char * const MySQLDB::PASSWORD {::getenv("MYGRATE_MYSQL_PASSWORD")};
- const unsigned short MySQLDB::PORT {(unsigned short)std::atoi(MyGrate::getenv("MYGRATE_MYSQL_PORT", "3306"))};
+ const unsigned short MySQLDB::PORT {
+ static_cast<unsigned short>(std::atoi(MyGrate::getenv("MYGRATE_MYSQL_PORT", "3306")))};
std::size_t MySQLDB::mocknum;
MySQLDB::MySQLDB() :