summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-02-16 14:21:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2019-02-16 14:21:28 +0000
commit463dd49304a47b835d1818d7489fe7ba373890ac (patch)
tree6375ec8634cebb237ade975eb802b4221f569afd
parentMore clang tidy fixes (diff)
downloadlibdbpp-463dd49304a47b835d1818d7489fe7ba373890ac.tar.bz2
libdbpp-463dd49304a47b835d1818d7489fe7ba373890ac.tar.xz
libdbpp-463dd49304a47b835d1818d7489fe7ba373890ac.zip
Modernize clang tidy fixes
-rw-r--r--Jamroot.jam1
-rw-r--r--libdbpp/column.cpp6
-rw-r--r--libdbpp/command.cpp12
-rw-r--r--libdbpp/command.h6
-rw-r--r--libdbpp/connection.cpp6
-rw-r--r--libdbpp/connection.h8
-rw-r--r--libdbpp/connectionPool.cpp4
-rw-r--r--libdbpp/connectionPool.h2
-rw-r--r--libdbpp/createMockDb.cpp2
-rw-r--r--libdbpp/error.cpp13
-rw-r--r--libdbpp/error.h8
-rw-r--r--libdbpp/mockDatabase.cpp4
-rw-r--r--libdbpp/mockDatabase.h2
-rw-r--r--libdbpp/modifycommand.cpp4
-rw-r--r--libdbpp/modifycommand.h2
-rw-r--r--libdbpp/selectcommand.cpp10
-rw-r--r--libdbpp/selectcommand.h6
-rw-r--r--libdbpp/sqlParse.h4
-rw-r--r--libdbpp/sqlParseImpl.cpp8
-rw-r--r--libdbpp/sqlWriter.cpp4
-rw-r--r--libdbpp/sqlWriter.h2
-rw-r--r--libdbpp/tablepatch.cpp4
m---------libdbpp/unittests/libdbpp-mysql0
m---------libdbpp/unittests/libdbpp-postgresql0
-rw-r--r--libdbpp/unittests/testParse.cpp6
-rw-r--r--libdbpp/unittests/testUtils.cpp8
26 files changed, 47 insertions, 85 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index c9d6c33..6857f8a 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -19,6 +19,7 @@ project
<toolset>tidy:<checkxx>bugprone-*
<toolset>tidy:<checkxx>clang-*
<toolset>tidy:<checkxx>misc-*
+ <toolset>tidy:<checkxx>modernize-*
;
build-project libdbpp ;
diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp
index a02ba01..512d083 100644
--- a/libdbpp/column.cpp
+++ b/libdbpp/column.cpp
@@ -17,7 +17,7 @@ static
std::string
demangle(const char * const mangled)
{
- std::unique_ptr<char, decltype(&free)> r(abi::__cxa_demangle(mangled, NULL, NULL, NULL), &free);
+ std::unique_ptr<char, decltype(&free)> r(abi::__cxa_demangle(mangled, nullptr, nullptr, nullptr), &free);
return &*r;
};
@@ -25,7 +25,7 @@ InvalidConversion::InvalidConversion(const char * const f, const char * const t)
AdHocFormatter(InvalidConversionMsg, "Invalid conversion from column type (%?) to value type (%?)");
std::string
-InvalidConversion::message() const throw()
+InvalidConversion::message() const noexcept
{
return InvalidConversionMsg::get(from, to);
}
@@ -34,7 +34,7 @@ UnexpectedNullValue::UnexpectedNullValue(const char * const t) : to(t) { }
AdHocFormatter(UnexpectedNullValueMsg, "Unexpected null value in column expecting type (%?)");
std::string
-UnexpectedNullValue::message() const throw()
+UnexpectedNullValue::message() const noexcept
{
return InvalidConversionMsg::get(to, to);
}
diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp
index 551f4bc..0c97403 100644
--- a/libdbpp/command.cpp
+++ b/libdbpp/command.cpp
@@ -6,21 +6,13 @@ INSTANTIATEFACTORY(DB::CommandOptions, std::size_t, const DB::CommandOptionsMap
NAMEDFACTORY("", DB::CommandOptions, DB::CommandOptionsFactory);
PLUGINRESOLVER(DB::CommandOptionsFactory, DB::Connection::resolvePlugin);
-DB::Command::Command(const std::string & s) :
- sql(s)
+DB::Command::Command(std::string s) :
+ sql(std::move(s))
{
}
DB::Command::~Command() = default;
-DB::ParameterTypeNotSupported::ParameterTypeNotSupported()
-{
-}
-
-DB::ParameterOutOfRange::ParameterOutOfRange()
-{
-}
-
DB::CommandOptions::CommandOptions(std::size_t h, const CommandOptionsMap &) :
hash(h)
{
diff --git a/libdbpp/command.h b/libdbpp/command.h
index c9092b0..6f66559 100644
--- a/libdbpp/command.h
+++ b/libdbpp/command.h
@@ -15,14 +15,10 @@
namespace DB {
/// Exception thrown when binding a parameter of type the connector doesn't support.
class DLL_PUBLIC ParameterTypeNotSupported : public Error {
- public:
- ParameterTypeNotSupported();
};
/// Exception thrown when binding a parameter out of range of those defined in the command.
class DLL_PUBLIC ParameterOutOfRange : public Error {
- public:
- ParameterOutOfRange();
};
/// Represents the basic options that can be passed when creating new commands.
@@ -59,7 +55,7 @@ namespace DB {
class DLL_PUBLIC Command {
public:
/// Creates a new command from the given SQL.
- Command(const std::string & sql);
+ Command(std::string sql);
virtual ~Command() = 0;
/// Bind an integer to parameter i.
diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp
index a3ae615..8050d06 100644
--- a/libdbpp/connection.cpp
+++ b/libdbpp/connection.cpp
@@ -8,12 +8,12 @@
#include <system_error>
DB::ConnectionError::ConnectionError() :
- FailureTime(time(NULL))
+ FailureTime(time(nullptr))
{
}
std::string
-DB::TransactionStillOpen::message() const throw()
+DB::TransactionStillOpen::message() const noexcept
{
return "A transaction is still open.";
}
@@ -178,7 +178,7 @@ DB::Connection::insertId()
}
std::string
-DB::TransactionRequired::message() const throw()
+DB::TransactionRequired::message() const noexcept
{
return "A transaction must be opened before performing this operation";
}
diff --git a/libdbpp/connection.h b/libdbpp/connection.h
index 2d4bc9b..c7efce4 100644
--- a/libdbpp/connection.h
+++ b/libdbpp/connection.h
@@ -67,25 +67,25 @@ namespace DB {
/// Exception thrown when finishing a connection that still has a transaction open.
class DLL_PUBLIC TransactionStillOpen : public AdHoc::StdException {
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Exception thrown when attempting to open a transaction when one is already open.
class DLL_PUBLIC TransactionAlreadyOpen : public AdHoc::StdException {
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Exception thrown when attempting to perform a table patch with invalid settings.
class DLL_PUBLIC PatchCheckFailure : public AdHoc::StdException {
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Exception thrown when attempting to perform an action that requires a transaction when one is not open.
class DLL_PUBLIC TransactionRequired : public AdHoc::StdException {
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Base class for connections to a database.
diff --git a/libdbpp/connectionPool.cpp b/libdbpp/connectionPool.cpp
index 0eda241..d61a1a4 100644
--- a/libdbpp/connectionPool.cpp
+++ b/libdbpp/connectionPool.cpp
@@ -10,10 +10,10 @@ namespace DB {
{
}
- ConnectionPool::ConnectionPool(unsigned int m, unsigned int k, const std::string & t, const std::string & cs) :
+ ConnectionPool::ConnectionPool(unsigned int m, unsigned int k, const std::string & t, std::string cs) :
BasicConnectionPool(m, k),
factory(ConnectionFactory::get(t)),
- connectionString(cs)
+ connectionString(std::move(cs))
{
}
diff --git a/libdbpp/connectionPool.h b/libdbpp/connectionPool.h
index f7760aa..e03b6c8 100644
--- a/libdbpp/connectionPool.h
+++ b/libdbpp/connectionPool.h
@@ -30,7 +30,7 @@ namespace DB {
/// @param keep Number of connections to keep open after use.
/// @param type Database connection factory name.
/// @param connectionString Connection string to pass to the connection factory.
- ConnectionPool(unsigned int max, unsigned int keep, const std::string & type, const std::string & connectionString);
+ ConnectionPool(unsigned int max, unsigned int keep, const std::string & type, std::string connectionString);
protected:
/// Create a new connection.
diff --git a/libdbpp/createMockDb.cpp b/libdbpp/createMockDb.cpp
index a4d5638..f690f6c 100644
--- a/libdbpp/createMockDb.cpp
+++ b/libdbpp/createMockDb.cpp
@@ -1,7 +1,7 @@
#include <iostream>
#include <boost/program_options.hpp>
#include <filesystem>
-#include <signal.h>
+#include <csignal>
#include "mockDatabase.h"
namespace po = boost::program_options;
diff --git a/libdbpp/error.cpp b/libdbpp/error.cpp
deleted file mode 100644
index 5d0a937..0000000
--- a/libdbpp/error.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "error.h"
-#include <time.h>
-
-namespace DB {
- ColumnTypeNotSupported::ColumnTypeNotSupported()
- {
- }
-
- BulkUploadNotSupported::BulkUploadNotSupported()
- {
- }
-}
-
diff --git a/libdbpp/error.h b/libdbpp/error.h
index c36d864..7c36281 100644
--- a/libdbpp/error.h
+++ b/libdbpp/error.h
@@ -12,14 +12,10 @@ namespace DB {
/// Exception thrown when attempting to bulk upload with a connector that doesn't support it.
class DLL_PUBLIC BulkUploadNotSupported : public Error {
- public:
- BulkUploadNotSupported();
};
/// Exception thrown when a query returns an unsupported column type.
class DLL_PUBLIC ColumnTypeNotSupported : public Error {
- public:
- ColumnTypeNotSupported();
};
/// Exception thrown on an attempt to convert betweem incompatible types.
@@ -31,7 +27,7 @@ namespace DB {
InvalidConversion(const char * const from, const char * const to);
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
const std::string from;
const std::string to;
};
@@ -43,7 +39,7 @@ namespace DB {
UnexpectedNullValue(const char * const from);
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
const char * to;
};
}
diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp
index bdc151c..7f06b6c 100644
--- a/libdbpp/mockDatabase.cpp
+++ b/libdbpp/mockDatabase.cpp
@@ -61,10 +61,6 @@ MockServerDatabase::MockServerDatabase(const std::string & masterdb, const std::
{
}
-MockServerDatabase::~MockServerDatabase()
-{
-}
-
const std::string &
MockServerDatabase::databaseName() const
{
diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h
index 11a1bbd..bf02c4a 100644
--- a/libdbpp/mockDatabase.h
+++ b/libdbpp/mockDatabase.h
@@ -44,7 +44,7 @@ class DLL_PUBLIC MockServerDatabase : public MockDatabase {
/// @param name the prefix to use when creating databases.
/// @param type the database type.
MockServerDatabase(const std::string & masterdb, const std::string & name, const std::string & type);
- virtual ~MockServerDatabase();
+ virtual ~MockServerDatabase() = default;
/// Get the database instance name on the server.
const std::string & databaseName() const;
diff --git a/libdbpp/modifycommand.cpp b/libdbpp/modifycommand.cpp
index 7fd2685..79c8244 100644
--- a/libdbpp/modifycommand.cpp
+++ b/libdbpp/modifycommand.cpp
@@ -5,7 +5,3 @@ DB::ModifyCommand::ModifyCommand(const std::string & s) :
{
}
-DB::NoRowsAffected::NoRowsAffected()
-{
-}
-
diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h
index c05792c..b948479 100644
--- a/libdbpp/modifycommand.h
+++ b/libdbpp/modifycommand.h
@@ -8,8 +8,6 @@
namespace DB {
/// Exception thrown when an update affected no rows when some were expected.
class DLL_PUBLIC NoRowsAffected : public Error {
- public:
- NoRowsAffected();
};
/// Presents a command not expected to return any data.
diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp
index 661484c..568b95b 100644
--- a/libdbpp/selectcommand.cpp
+++ b/libdbpp/selectcommand.cpp
@@ -12,24 +12,24 @@ namespace DB {
AdHocFormatter(ColumnIndexOutOfRangeMsg, "Column (%?) index out of range");
std::string
- ColumnIndexOutOfRange::message() const throw()
+ ColumnIndexOutOfRange::message() const noexcept
{
return ColumnIndexOutOfRangeMsg::get(colNo);
}
- ColumnDoesNotExist::ColumnDoesNotExist(const Glib::ustring & n) : colName(n) { }
+ ColumnDoesNotExist::ColumnDoesNotExist(Glib::ustring n) : colName(std::move(n)) { }
AdHocFormatter(ColumnDoesNotExistMsg, "Column (%?) does not exist");
std::string
- ColumnDoesNotExist::message() const throw()
+ ColumnDoesNotExist::message() const noexcept
{
return ColumnDoesNotExistMsg::get(colName);
}
- typedef boost::multi_index_container<ColumnPtr, boost::multi_index::indexed_by<
+ using ColumnsBase = boost::multi_index_container<ColumnPtr, boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<boost::multi_index::member<DB::Column, const unsigned int, &DB::Column::colNo>>,
boost::multi_index::ordered_unique<boost::multi_index::member<DB::Column, const std::string, &DB::Column::name>>
- >> ColumnsBase;
+ >>;
class SelectCommand::Columns : public ColumnsBase { };
};
diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h
index 2fb9253..871b332 100644
--- a/libdbpp/selectcommand.h
+++ b/libdbpp/selectcommand.h
@@ -83,7 +83,7 @@ namespace DB {
const unsigned int colNo;
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Exception thrown when the requested column does not exist in the result set.
@@ -91,13 +91,13 @@ namespace DB {
public:
/// New ColumnDoesNotExist exception
/// @param n Name requested
- ColumnDoesNotExist(const Glib::ustring & n);
+ ColumnDoesNotExist(Glib::ustring n);
/// Name requested
const Glib::ustring colName;
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
};
/// Represents a command expected to return data to the client.
diff --git a/libdbpp/sqlParse.h b/libdbpp/sqlParse.h
index fc6b4c9..20d6c0e 100644
--- a/libdbpp/sqlParse.h
+++ b/libdbpp/sqlParse.h
@@ -21,7 +21,7 @@ namespace DB {
SqlParseException(const char * what, unsigned int line);
private:
- std::string message() const throw() override;
+ std::string message() const noexcept override;
const char * reason;
const unsigned int line;
};
@@ -29,7 +29,7 @@ namespace DB {
/// @cond
class DLL_PUBLIC SqlParse : public yyFlexLexer {
public:
- SqlParse(std::istream &, const std::filesystem::path &);
+ SqlParse(std::istream &, std::filesystem::path);
void Execute();
diff --git a/libdbpp/sqlParseImpl.cpp b/libdbpp/sqlParseImpl.cpp
index a187ba7..f646dbe 100644
--- a/libdbpp/sqlParseImpl.cpp
+++ b/libdbpp/sqlParseImpl.cpp
@@ -7,14 +7,14 @@ namespace DB {
AdHocFormatter(SqlParseExceptionMsg, "Error parsing SQL script: %? at line %?");
std::string
- SqlParseException::message() const throw()
+ SqlParseException::message() const noexcept
{
return SqlParseExceptionMsg::get(reason, line);
}
- SqlParse::SqlParse(std::istream & f, const std::filesystem::path & s) :
- yyFlexLexer(&f, NULL),
- scriptDir(s)
+ SqlParse::SqlParse(std::istream & f, std::filesystem::path s) :
+ yyFlexLexer(&f, nullptr),
+ scriptDir(std::move(s))
{
if (!f.good()) {
throw SqlParseException("Script stream not in good state.", 0);
diff --git a/libdbpp/sqlWriter.cpp b/libdbpp/sqlWriter.cpp
index 8d588dd..328893c 100644
--- a/libdbpp/sqlWriter.cpp
+++ b/libdbpp/sqlWriter.cpp
@@ -5,8 +5,8 @@ DB::SqlWriter::bindParams(DB::Command *, unsigned int &)
{
}
-DB::StaticSqlWriter::StaticSqlWriter(const std::string & s) :
- sql(s)
+DB::StaticSqlWriter::StaticSqlWriter(std::string s) :
+ sql(std::move(s))
{
}
diff --git a/libdbpp/sqlWriter.h b/libdbpp/sqlWriter.h
index ff1c51c..45c84a9 100644
--- a/libdbpp/sqlWriter.h
+++ b/libdbpp/sqlWriter.h
@@ -25,7 +25,7 @@ namespace DB {
public:
/// Construct with the SQL to write.
/// @param sql The SQL to write.
- StaticSqlWriter(const std::string & sql);
+ StaticSqlWriter(std::string sql);
/// Append the SQL to the buffer.
/// @param buffer The buffer
void writeSql(AdHoc::Buffer & buffer);
diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp
index 5df2aca..d270d7c 100644
--- a/libdbpp/tablepatch.cpp
+++ b/libdbpp/tablepatch.cpp
@@ -65,7 +65,7 @@ appendIf(AdHoc::Buffer & buf, const Container & c, const std::function<bool(cons
{
auto fmt = AdHoc::Buffer::getFormat(fmts);
unsigned int x = 0;
- for (typename Container::const_iterator i = c.begin(); i != c.end(); ++i) {
+ for (auto i = c.begin(); i != c.end(); ++i) {
if (sel(i)) {
if (x > 0) {
buf.appendbf("%s", sep);
@@ -366,7 +366,7 @@ DB::Connection::patchInserts(TablePatch * tp)
}
std::string
-DB::PatchCheckFailure::message() const throw()
+DB::PatchCheckFailure::message() const noexcept
{
return "Santiy checks failed: check table names and keys";
}
diff --git a/libdbpp/unittests/libdbpp-mysql b/libdbpp/unittests/libdbpp-mysql
-Subproject f4a4a323588410d083dd9ec1145de922db43f80
+Subproject b8ddecf41c8938136b3f4a081e1b8a98584c240
diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql
-Subproject 6b913137275cacde9f938058f961d4cbb64f584
+Subproject 1ca0cd42419656cf4a4b9e37c5f3cfb51ccafbb
diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp
index dcd11d6..d63925b 100644
--- a/libdbpp/unittests/testParse.cpp
+++ b/libdbpp/unittests/testParse.cpp
@@ -9,7 +9,7 @@
#include <error.h>
#include <sqlParse.h>
-typedef std::vector<std::string> SQLs;
+using SQLs = std::vector<std::string>;
BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(SQLs);
class RecordingParser : std::fstream, public DB::SqlParse {
@@ -20,12 +20,12 @@ class RecordingParser : std::fstream, public DB::SqlParse {
{
}
- void Comment(const std::string & c) const
+ void Comment(const std::string & c) const override
{
comments.push_back(c);
}
- void Statement(const std::string & s) const
+ void Statement(const std::string & s) const override
{
executed.push_back(s);
}
diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp
index 092140b..416d359 100644
--- a/libdbpp/unittests/testUtils.cpp
+++ b/libdbpp/unittests/testUtils.cpp
@@ -32,7 +32,7 @@ BOOST_AUTO_TEST_CASE( forEachRow )
BOOST_REQUIRE_EQUAL(1, a);
BOOST_REQUIRE_CLOSE(4.3, b, 0.001);
BOOST_REQUIRE_EQUAL("Some text", c);
- BOOST_REQUIRE_EQUAL(boost::posix_time::ptime_from_tm({ 17, 39, 13, 7, 10, 115, 0, 0, 0, 0, 0}), d);
+ BOOST_REQUIRE_EQUAL(boost::posix_time::ptime_from_tm({ 17, 39, 13, 7, 10, 115, 0, 0, 0, 0, nullptr}), d);
BOOST_REQUIRE_EQUAL(boost::posix_time::time_duration(4, 3, 2), e);
BOOST_REQUIRE_EQUAL(true, f);
});
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE( bulkLoadFile )
});
}
-typedef boost::mpl::list<std::string, std::string_view, Glib::ustring> StringTypes;
+using StringTypes = boost::mpl::list<std::string, std::string_view, Glib::ustring>;
BOOST_AUTO_TEST_CASE_TEMPLATE( nullBind, Str, StringTypes )
{
auto db = DB::MockDatabase::openConnectionTo("pqmock");
@@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE( charStarBindNull )
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
db->modify("DELETE FROM forEachRow")->execute();
auto ins = db->modify("INSERT INTO forEachRow(a, c) VALUES(?, ?)");
- char * cs = NULL;
+ char * cs = nullptr;
char * cs2 = strdup("a thing");
ins->bindParamS(0, cs);
ins->bindParamS(1, cs2);
@@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE( bindIntPtr )
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("pqmock"));
db->modify("DELETE FROM forEachRow")->execute();
auto ins = db->modify("INSERT INTO forEachRow(a, b) VALUES(?, ?)");
- int * is = NULL;
+ int * is = nullptr;
int * is2 = new int(53);
ins->bindParamI(0, is);
ins->bindParamI(1, is2);