From 7b56849be41fdd342c8d92c243df6370a53c8305 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Sep 2021 14:24:56 +0100 Subject: Add JT recommended warnings --- libmysqlpp/Jamfile.jam | 15 +++++++++++++++ libmysqlpp/my-column.cpp | 4 +++- libmysqlpp/my-column.h | 3 +++ libmysqlpp/my-command.cpp | 16 ++++++++-------- libmysqlpp/my-command.h | 3 +++ libmysqlpp/my-connection.cpp | 16 ++++++---------- libmysqlpp/my-connection.h | 3 +++ libmysqlpp/my-error.h | 3 +++ libmysqlpp/my-mock.cpp | 2 +- libmysqlpp/my-modifycommand.cpp | 4 ++-- libmysqlpp/unittests/testmysql.cpp | 8 ++++---- 11 files changed, 51 insertions(+), 26 deletions(-) (limited to 'libmysqlpp') diff --git a/libmysqlpp/Jamfile.jam b/libmysqlpp/Jamfile.jam index 6ddd57d..8894db4 100644 --- a/libmysqlpp/Jamfile.jam +++ b/libmysqlpp/Jamfile.jam @@ -16,6 +16,21 @@ project release:on debug:extra debug:on + debug:-Wnon-virtual-dtor + debug:-Wold-style-cast + debug:-Wcast-align + debug:-Wunused + debug:-Woverloaded-virtual + debug:-Wpedantic + debug:-Wconversion + debug:-Wsign-conversion + debug:-Wnull-dereference + debug:-Wdouble-promotion + debug:-Wformat=2 + gcc,debug:-Wduplicated-cond + gcc,debug:-Wduplicated-branches + gcc,debug:-Wlogical-op + gcc,debug:-Wuseless-cast coverage:on tidy:misc-non-private-member-variables-in-classes ; diff --git a/libmysqlpp/my-column.cpp b/libmysqlpp/my-column.cpp index c205439..4a5cdbf 100644 --- a/libmysqlpp/my-column.cpp +++ b/libmysqlpp/my-column.cpp @@ -89,7 +89,9 @@ namespace MySQL { h.null(); } else { - h.timestamp(boost::posix_time::ptime(boost::gregorian::date(value.year, value.month, value.day), + h.timestamp(boost::posix_time::ptime( + boost::gregorian::date(static_cast(value.year), + static_cast(value.month), static_cast(value.day)), boost::posix_time::time_duration(value.hour, value.minute, value.second) + boost::posix_time::microseconds(value.second_part))); } diff --git a/libmysqlpp/my-column.h b/libmysqlpp/my-column.h index 2726830..966216c 100644 --- a/libmysqlpp/my-column.h +++ b/libmysqlpp/my-column.h @@ -2,7 +2,10 @@ #define MY_COLUMN_H #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop namespace MySQL { class SelectCommand; diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp index 7e7275a..114e526 100644 --- a/libmysqlpp/my-command.cpp +++ b/libmysqlpp/my-command.cpp @@ -124,10 +124,10 @@ MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::ptime & v) ts.year = v.date().year(); ts.month = v.date().month(); ts.day = v.date().day(); - ts.hour = v.time_of_day().hours(); - ts.minute = v.time_of_day().minutes(); - ts.second = v.time_of_day().seconds(); - ts.second_part = v.time_of_day().total_microseconds() % 1000000; + ts.hour = static_cast(v.time_of_day().hours()); + ts.minute = static_cast(v.time_of_day().minutes()); + ts.second = static_cast(v.time_of_day().seconds()); + ts.second_part = static_cast(v.time_of_day().total_microseconds() % 1000000U); ts.neg = false; } void @@ -140,10 +140,10 @@ MySQL::Command::bindParamT(unsigned int n, const boost::posix_time::time_duratio ts.year = 0; ts.month = 0; ts.day = 0; - ts.hour = v.hours(); - ts.minute = v.minutes(); - ts.second = v.seconds(); - ts.second_part = v.total_microseconds() % 1000000; + ts.hour = static_cast(v.hours()); + ts.minute = static_cast(v.minutes()); + ts.second = static_cast(v.seconds()); + ts.second_part = static_cast(v.total_microseconds() % 1000000U); ts.neg = (v.is_negative() ? 1 : 0); } void diff --git a/libmysqlpp/my-command.h b/libmysqlpp/my-command.h index 1161b77..87347cf 100644 --- a/libmysqlpp/my-command.h +++ b/libmysqlpp/my-command.h @@ -2,7 +2,10 @@ #define MY_COMMAND_H #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop #include namespace MySQL { diff --git a/libmysqlpp/my-connection.cpp b/libmysqlpp/my-connection.cpp index 5828986..22ba809 100644 --- a/libmysqlpp/my-connection.cpp +++ b/libmysqlpp/my-connection.cpp @@ -8,22 +8,18 @@ #include #include -NAMEDFACTORY("mysql", MySQL::Connection, DB::ConnectionFactory); +NAMEDFACTORY("mysql", MySQL::Connection, DB::ConnectionFactory) MySQL::ConnectionError::ConnectionError(MYSQL * m) : MySQL::Error(m) { } class Opts { public: - Opts() - { - port = 3306; - } using OptString = std::optional; OptString server; OptString user; OptString password; OptString database; - unsigned int port; + unsigned int port {3306}; OptString unix_socket; OptString options; }; @@ -158,13 +154,13 @@ namespace MySQL { ctx->swapContext(); if (ctx->loadBufLen == ctx->bufOff) { // Nothing to do or error - return ctx->bufOff; + return static_cast(ctx->bufOff); } } auto copy = std::min(ctx->loadBufLen - ctx->bufOff, bufSize); memcpy(buf, ctx->loadBuf + ctx->bufOff, copy); ctx->bufOff += copy; - return copy; + return static_cast(copy); } static void @@ -215,7 +211,7 @@ MySQL::Connection::endBulkUpload(const char * msg) } ctx->loadBuf = nullptr; ctx->loadBufLen = 0; - ctx->bufOff = msg ? -1 : 0; + ctx->bufOff = msg ? static_cast(-1) : 0; // switch context with empty buffer fires finished ctx->swapContext(); // Check result @@ -245,5 +241,5 @@ MySQL::Connection::bulkUploadData(const char * data, size_t len) const int64_t MySQL::Connection::insertId() { - return mysql_insert_id(&conn); + return static_cast(mysql_insert_id(&conn)); } diff --git a/libmysqlpp/my-connection.h b/libmysqlpp/my-connection.h index 184dafe..f0edacc 100644 --- a/libmysqlpp/my-connection.h +++ b/libmysqlpp/my-connection.h @@ -4,7 +4,10 @@ #include "my-error.h" #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop namespace MySQL { class ConnectionError : public virtual Error, public virtual DB::ConnectionError { diff --git a/libmysqlpp/my-error.h b/libmysqlpp/my-error.h index 85fff63..2dfc99b 100644 --- a/libmysqlpp/my-error.h +++ b/libmysqlpp/my-error.h @@ -3,7 +3,10 @@ #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop namespace MySQL { class Error : public AdHoc::Exception { diff --git a/libmysqlpp/my-mock.cpp b/libmysqlpp/my-mock.cpp index 52d4899..27e9df2 100644 --- a/libmysqlpp/my-mock.cpp +++ b/libmysqlpp/my-mock.cpp @@ -2,7 +2,7 @@ #include "my-connection.h" #include -NAMEDFACTORY("mysql", MySQL::Mock, DB::MockDatabaseFactory); +NAMEDFACTORY("mysql", MySQL::Mock, DB::MockDatabaseFactory) namespace MySQL { diff --git a/libmysqlpp/my-modifycommand.cpp b/libmysqlpp/my-modifycommand.cpp index dd607b3..9714638 100644 --- a/libmysqlpp/my-modifycommand.cpp +++ b/libmysqlpp/my-modifycommand.cpp @@ -15,9 +15,9 @@ MySQL::ModifyCommand::execute(bool anc) if (mysql_stmt_execute(stmt.get())) { throw Error(stmt.get()); } - int rows = mysql_stmt_affected_rows(stmt.get()); + auto rows = mysql_stmt_affected_rows(stmt.get()); if (rows == 0 && !anc) { throw DB::NoRowsAffected(); } - return rows; + return static_cast(rows); } diff --git a/libmysqlpp/unittests/testmysql.cpp b/libmysqlpp/unittests/testmysql.cpp index 2f60e68..fdfb0a8 100644 --- a/libmysqlpp/unittests/testmysql.cpp +++ b/libmysqlpp/unittests/testmysql.cpp @@ -21,7 +21,7 @@ public: BOOST_GLOBAL_FIXTURE(StandardMockDatabase); -BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore); +BOOST_FIXTURE_TEST_SUITE(Core, DB::TestCore) BOOST_AUTO_TEST_CASE(transactions) { @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(bulkload) } std::array buf {}; for (std::streamsize r; (r = in.readsome(buf.data(), buf.size())) > 0;) { - ro->bulkUploadData(buf.data(), r); + ro->bulkUploadData(buf.data(), static_cast(r)); } ro->endBulkUpload(nullptr); assertScalarValueHelper(*count, 800); @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(insertId) { auto ro = DB::MockDatabase::openConnectionTo("mysqlmock"); auto ins = ro->modify("INSERT INTO inserts(num) VALUES(?)"); - int prevId = 0; + int64_t prevId = 0; for (int n : {4, 40, -4}) { ins->bindParamI(0, n); ins->execute(); @@ -150,4 +150,4 @@ BOOST_AUTO_TEST_CASE(errors) BOOST_REQUIRE_THROW((void)DB::ConnectionFactory::createNew("mysql", "server=nohost"), DB::ConnectionError); } -BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3