From 2128f927d13312e77f4639b08fa9753ed560064f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 21 Sep 2021 17:59:58 +0100 Subject: First commit passing IWYU --- Jamroot.jam | 1 + iwyu.json | 181 +++++++++++++++++++++++++++++++ libdbpp/Jamfile.jam | 1 + libdbpp/column.cpp | 6 +- libdbpp/column.h | 14 ++- libdbpp/command.cpp | 4 +- libdbpp/command.h | 14 ++- libdbpp/connection.cpp | 5 +- libdbpp/connection.h | 11 +- libdbpp/connectionPool.cpp | 2 + libdbpp/connectionPool.h | 7 +- libdbpp/createMockDb.cpp | 10 ++ libdbpp/dbTypes.cpp | 2 +- libdbpp/mockDatabase.cpp | 6 +- libdbpp/mockDatabase.h | 8 +- libdbpp/modifycommand.h | 1 + libdbpp/selectcommand.cpp | 7 +- libdbpp/selectcommand.h | 18 ++- libdbpp/sqlParseImpl.cpp | 4 + libdbpp/sqlWriter.cpp | 2 + libdbpp/sqlWriter.h | 5 +- libdbpp/tablepatch.cpp | 6 +- libdbpp/tablepatch.h | 6 +- libdbpp/testCore.cpp | 12 +- libdbpp/testCore.h | 8 +- libdbpp/unittests/libdbpp-mysql | 2 +- libdbpp/unittests/libdbpp-odbc | 2 +- libdbpp/unittests/libdbpp-postgresql | 2 +- libdbpp/unittests/libdbpp-sqlite | 2 +- libdbpp/unittests/mockdb.cpp | 7 ++ libdbpp/unittests/mockdb.h | 5 + libdbpp/unittests/testConnection.cpp | 11 +- libdbpp/unittests/testConnectionPool.cpp | 4 + libdbpp/unittests/testMock.cpp | 11 +- libdbpp/unittests/testParse.cpp | 6 +- libdbpp/unittests/testPatch.cpp | 8 ++ libdbpp/unittests/testUtils.cpp | 39 ++++++- 37 files changed, 385 insertions(+), 55 deletions(-) create mode 100644 iwyu.json diff --git a/Jamroot.jam b/Jamroot.jam index ed164f9..2add787 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -42,6 +42,7 @@ project tidy:hicpp-* tidy:hicpp-named-parameter tidy:performance-* + tidy:iwyu.json tidy:boost tidy:std ; diff --git a/iwyu.json b/iwyu.json new file mode 100644 index 0000000..321a158 --- /dev/null +++ b/iwyu.json @@ -0,0 +1,181 @@ +[ + { + "symbol": [ + "Glib::ustring", + "private", + "", + "public" + ] + }, + { + "symbol": [ + "@u?int\\d\\+_t", + "private", + "", + "public" + ] + }, + { + "symbol": [ + "boost::posix_time::time_duration", + "private", + "", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "symbol": [ + "free", + "private", + "", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "symbol": [ + "Oid", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "ref": "/usr/lib/llvm/12/share/include-what-you-use/boost-all-private.imp" + } +] diff --git a/libdbpp/Jamfile.jam b/libdbpp/Jamfile.jam index a5b9a88..06e5f5a 100644 --- a/libdbpp/Jamfile.jam +++ b/libdbpp/Jamfile.jam @@ -39,6 +39,7 @@ exe createmockdb : createMockDb.cpp : : dbppcore + adhocutil stdc++fs boost_program_options ; diff --git a/libdbpp/column.cpp b/libdbpp/column.cpp index 8b13462..7190d36 100644 --- a/libdbpp/column.cpp +++ b/libdbpp/column.cpp @@ -1,9 +1,13 @@ #include "column.h" #include +#include #include -#include #include +namespace Glib { + class ustring; +} + namespace DB { Column::Column(const Glib::ustring & n, unsigned int i) : colNo(i), name(n.collate_key()) { } diff --git a/libdbpp/column.h b/libdbpp/column.h index f3c97be..11a4658 100644 --- a/libdbpp/column.h +++ b/libdbpp/column.h @@ -1,11 +1,8 @@ #ifndef DB_COLUMN_H #define DB_COLUMN_H -#include "dbTypes.h" #include "error.h" -#include #include -#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wsign-conversion" @@ -14,11 +11,21 @@ #endif #include #pragma GCC diagnostic pop +#include +#include #include #include +#include +#include +#include +#include #include +namespace boost::posix_time { + class time_duration; +} namespace DB { + class Blob; /// Abstract class for something that can handle field data. See Column::apply. class DLL_PUBLIC HandleField { public: @@ -44,7 +51,6 @@ namespace DB { virtual void blob(const Blob &); }; - class Command; /// Represents a column in a result set and provides access to the current rows data. class DLL_PUBLIC Column { public: diff --git a/libdbpp/command.cpp b/libdbpp/command.cpp index f2c6934..dc7922a 100644 --- a/libdbpp/command.cpp +++ b/libdbpp/command.cpp @@ -1,6 +1,8 @@ #include "command.h" #include "connection.h" #include +#include +#include INSTANTIATEFACTORY(DB::CommandOptions, std::size_t, const DB::CommandOptionsMap &) NAMEDFACTORY("", DB::CommandOptions, DB::CommandOptionsFactory) @@ -8,8 +10,6 @@ PLUGINRESOLVER(DB::CommandOptionsFactory, DB::Connection::resolvePlugin) DB::Command::Command(std::string s) : sql(std::move(s)) { } -DB::Command::~Command() = default; - DB::CommandOptions::CommandOptions(std::size_t h, const CommandOptionsMap &) : hash(h) { } bool diff --git a/libdbpp/command.h b/libdbpp/command.h index e368b5c..8c3262b 100644 --- a/libdbpp/command.h +++ b/libdbpp/command.h @@ -2,12 +2,15 @@ #define DB_COMMAND_H #include "command_fwd.h" -#include "dbTypes.h" #include "error.h" -#include +#include #include #include +#include #include +#include +#include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wsign-conversion" @@ -16,11 +19,14 @@ #endif #include #pragma GCC diagnostic pop -#include #include #include +namespace boost::posix_time { + class time_duration; +} namespace DB { + class Blob; /// Exception thrown when binding a parameter of type the connector doesn't support. class DLL_PUBLIC ParameterTypeNotSupported : public Error { }; @@ -67,7 +73,7 @@ namespace DB { public: /// Creates a new command from the given SQL. explicit Command(std::string sql); - virtual ~Command() = 0; + virtual ~Command() = default; /// Standard special members SPECIAL_MEMBERS_COPY_RO(Command); diff --git a/libdbpp/connection.cpp b/libdbpp/connection.cpp index 4ba779d..531b5bb 100644 --- a/libdbpp/connection.cpp +++ b/libdbpp/connection.cpp @@ -1,10 +1,13 @@ #include "connection.h" #include "error.h" #include "modifycommand.h" -#include "selectcommand.h" +#include #include +#include +#include #include #include +#include #include DB::ConnectionError::ConnectionError() : FailureTime(time(nullptr)) { } diff --git a/libdbpp/connection.h b/libdbpp/connection.h index 9cd96e0..495c1c2 100644 --- a/libdbpp/connection.h +++ b/libdbpp/connection.h @@ -2,22 +2,23 @@ #define DB_CONNECTION_H #include "command_fwd.h" -#include "connection_fwd.h" #include "error.h" #include +#include +#include #include #include #include +#include #include #include #include #include +#include +#include +#include #include -namespace AdHoc { - class Buffer; -} - namespace DB { class TablePatch; diff --git a/libdbpp/connectionPool.cpp b/libdbpp/connectionPool.cpp index 5ee4f32..69eb732 100644 --- a/libdbpp/connectionPool.cpp +++ b/libdbpp/connectionPool.cpp @@ -1,5 +1,7 @@ #include "connectionPool.h" +#include #include +#include template class AdHoc::ResourcePool; template class AdHoc::ResourceHandle; diff --git a/libdbpp/connectionPool.h b/libdbpp/connectionPool.h index 877781e..8ee6ecd 100644 --- a/libdbpp/connectionPool.h +++ b/libdbpp/connectionPool.h @@ -2,8 +2,13 @@ #define DB_CONNECTIONPOOL_H #include "connection.h" +#include "connection_fwd.h" // for ConnectionPtr +#include "resourcePool.impl.h" // for ResourcePool<>::InUse, ResourcePool +#include // for operator!= #include -#include +//#include +#include +#include // for get #include namespace DB { diff --git a/libdbpp/createMockDb.cpp b/libdbpp/createMockDb.cpp index d917b95..aa47fba 100644 --- a/libdbpp/createMockDb.cpp +++ b/libdbpp/createMockDb.cpp @@ -1,8 +1,18 @@ #include "mockDatabase.h" +#include #include +#include #include +#include +#include +#include #include #include +#include +#include +#include +#include +// IWYU pragma: no_include namespace po = boost::program_options; namespace fs = std::filesystem; diff --git a/libdbpp/dbTypes.cpp b/libdbpp/dbTypes.cpp index 7c4a87a..70fd25f 100644 --- a/libdbpp/dbTypes.cpp +++ b/libdbpp/dbTypes.cpp @@ -1,5 +1,5 @@ #include "dbTypes.h" -#include +#include DB::Blob::Blob(const void * d, size_t l) : data(d), len(l) { } diff --git a/libdbpp/mockDatabase.cpp b/libdbpp/mockDatabase.cpp index 8c168cf..797a6af 100644 --- a/libdbpp/mockDatabase.cpp +++ b/libdbpp/mockDatabase.cpp @@ -1,11 +1,11 @@ #define BOOST_FILESYSTEM_DYN_LINK #define BOOST_FILESYSTEM_SOURCE #include "mockDatabase.h" +#include "connection.h" #include #include -#include -#include -#include +#include // IWYU pragma: keep +#include INSTANTIATEPLUGINOF(DB::MockDatabase) INSTANTIATEFACTORY( diff --git a/libdbpp/mockDatabase.h b/libdbpp/mockDatabase.h index ed38ef8..82de5e0 100644 --- a/libdbpp/mockDatabase.h +++ b/libdbpp/mockDatabase.h @@ -1,14 +1,18 @@ #ifndef DB_MOCKDATABASE_H #define DB_MOCKDATABASE_H -#include "connection.h" +#include "connection_fwd.h" +#include +#include #include +#include +#include #include #include #include namespace DB { - + class Connection; /// MockDatabase creates, registers and destroys a database suitable for unit testing. class DLL_PUBLIC MockDatabase : public AdHoc::AbstractPluginImplementation { public: diff --git a/libdbpp/modifycommand.h b/libdbpp/modifycommand.h index 00d729f..7b6011e 100644 --- a/libdbpp/modifycommand.h +++ b/libdbpp/modifycommand.h @@ -3,6 +3,7 @@ #include "command.h" #include "error.h" +#include #include namespace DB { diff --git a/libdbpp/selectcommand.cpp b/libdbpp/selectcommand.cpp index 171c1b7..f67fca0 100644 --- a/libdbpp/selectcommand.cpp +++ b/libdbpp/selectcommand.cpp @@ -1,11 +1,14 @@ #include "selectcommand.h" #include "error.h" #include -#include -#include +#include // IWYU pragma: keep +#include // IWYU pragma: keep #include #include +#include #include +#include +#include namespace DB { ColumnIndexOutOfRange::ColumnIndexOutOfRange(unsigned int n) : colNo(n) { } diff --git a/libdbpp/selectcommand.h b/libdbpp/selectcommand.h index ee85c5c..de931a5 100644 --- a/libdbpp/selectcommand.h +++ b/libdbpp/selectcommand.h @@ -3,9 +3,23 @@ #include "column.h" #include "command.h" -#include "error.h" +#include "dbTypes.h" // IWYU pragma: keep +#include +#include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wsign-conversion" +#ifndef __clang__ +# pragma GCC diagnostic ignored "-Wuseless-cast" +#endif +#include +#pragma GCC diagnostic pop +#include #include #include +#include +#include +#include #include #ifndef BOOST_TEST_MODULE @@ -15,7 +29,7 @@ #endif namespace DB { - class Column; + class Error; class SelectCommand; /// @cond diff --git a/libdbpp/sqlParseImpl.cpp b/libdbpp/sqlParseImpl.cpp index bb27c6e..7d00895 100644 --- a/libdbpp/sqlParseImpl.cpp +++ b/libdbpp/sqlParseImpl.cpp @@ -1,6 +1,10 @@ +#include "connection.h" #include "sqlParse.h" #include +#include #include +#include +#include namespace DB { SqlParseException::SqlParseException(const char * r, unsigned int l) : reason(r), line(l) { } diff --git a/libdbpp/sqlWriter.cpp b/libdbpp/sqlWriter.cpp index f0afe3d..84ae55b 100644 --- a/libdbpp/sqlWriter.cpp +++ b/libdbpp/sqlWriter.cpp @@ -1,4 +1,6 @@ #include "sqlWriter.h" +#include "buffer.h" +#include void DB::SqlWriter::bindParams(DB::Command *, unsigned int &) diff --git a/libdbpp/sqlWriter.h b/libdbpp/sqlWriter.h index 43aef2e..e2cfe2b 100644 --- a/libdbpp/sqlWriter.h +++ b/libdbpp/sqlWriter.h @@ -1,10 +1,13 @@ #ifndef DB_SQLWRITER_H #define DB_SQLWRITER_H -#include #include +#include #include +namespace AdHoc { + class Buffer; +} namespace DB { class Command; diff --git a/libdbpp/tablepatch.cpp b/libdbpp/tablepatch.cpp index bbad348..9484a74 100644 --- a/libdbpp/tablepatch.cpp +++ b/libdbpp/tablepatch.cpp @@ -1,10 +1,12 @@ #include "tablepatch.h" #include "connection.h" #include "modifycommand.h" -#include "selectcommand.h" +#include "selectcommand.h" // IWYU pragma: keep #include "sqlWriter.h" -#include +#include +#include #include +#include #include DB::PatchResult diff --git a/libdbpp/tablepatch.h b/libdbpp/tablepatch.h index be8aec0..d3265a6 100644 --- a/libdbpp/tablepatch.h +++ b/libdbpp/tablepatch.h @@ -1,13 +1,11 @@ #ifndef TABLEPATCH_H #define TABLEPATCH_H -#include +#include "command_fwd.h" #include -#include -#include -#include #include #include +#include namespace DB { class SqlWriter; diff --git a/libdbpp/testCore.cpp b/libdbpp/testCore.cpp index 4887a79..bb92cf4 100644 --- a/libdbpp/testCore.cpp +++ b/libdbpp/testCore.cpp @@ -1,12 +1,18 @@ #include "testCore.h" -#include -#include +#include "column.h" +#include +#include // IWYU pragma: keep +#include #include #include #include +#include +#include +namespace boost::posix_time { + class time_duration; +} namespace DB { - TestCore::TestCore() : testString("Some C String"), testDateTime(boost::posix_time::from_time_t(1430530593)), testInterval(boost::posix_time::time_duration(1, 2, 3)), testBlobData([]() { diff --git a/libdbpp/testCore.h b/libdbpp/testCore.h index ea1f01b..a7a261a 100644 --- a/libdbpp/testCore.h +++ b/libdbpp/testCore.h @@ -1,7 +1,13 @@ #ifndef DB_TESTCORE_H #define DB_TESTCORE_H -#include +#include "dbTypes.h" +#include +#include +#include +#include +#include +#include #include namespace DB { diff --git a/libdbpp/unittests/libdbpp-mysql b/libdbpp/unittests/libdbpp-mysql index 7b56849..a863051 160000 --- a/libdbpp/unittests/libdbpp-mysql +++ b/libdbpp/unittests/libdbpp-mysql @@ -1 +1 @@ -Subproject commit 7b56849be41fdd342c8d92c243df6370a53c8305 +Subproject commit a8630518c10667ff88f0e0846de98337743a5808 diff --git a/libdbpp/unittests/libdbpp-odbc b/libdbpp/unittests/libdbpp-odbc index 3eb8f4b..b7f71b7 160000 --- a/libdbpp/unittests/libdbpp-odbc +++ b/libdbpp/unittests/libdbpp-odbc @@ -1 +1 @@ -Subproject commit 3eb8f4b130eb815aa3ff7cfbb89d05ebce216350 +Subproject commit b7f71b71224238a8b7bdb76b6feb98db9bac7aa9 diff --git a/libdbpp/unittests/libdbpp-postgresql b/libdbpp/unittests/libdbpp-postgresql index 3e305e4..465ea24 160000 --- a/libdbpp/unittests/libdbpp-postgresql +++ b/libdbpp/unittests/libdbpp-postgresql @@ -1 +1 @@ -Subproject commit 3e305e46d818a28a9c1cbb814bdc3dd72605d803 +Subproject commit 465ea24362ee267cf83909efa0b5cdee689ff1f7 diff --git a/libdbpp/unittests/libdbpp-sqlite b/libdbpp/unittests/libdbpp-sqlite index 5c72a2b..f036fb3 160000 --- a/libdbpp/unittests/libdbpp-sqlite +++ b/libdbpp/unittests/libdbpp-sqlite @@ -1 +1 @@ -Subproject commit 5c72a2b6a0076d85ce12884bca3b1de89df4db1b +Subproject commit f036fb38fb75c1298f6729ffc2f7d411b5478854 diff --git a/libdbpp/unittests/mockdb.cpp b/libdbpp/unittests/mockdb.cpp index 30180b9..15e07fb 100644 --- a/libdbpp/unittests/mockdb.cpp +++ b/libdbpp/unittests/mockdb.cpp @@ -1,4 +1,11 @@ #include "mockdb.h" +#include "command_fwd.h" +#include "connection.h" +#include "connection_fwd.h" +#include "error.h" +#include "factory.h" +#include "mockDatabase.h" +#include // LCOV_EXCL_START diff --git a/libdbpp/unittests/mockdb.h b/libdbpp/unittests/mockdb.h index e9775c6..a511c70 100644 --- a/libdbpp/unittests/mockdb.h +++ b/libdbpp/unittests/mockdb.h @@ -1,8 +1,13 @@ #ifndef DB_MOCKDB_H #define DB_MOCKDB_H +#include "../command_fwd.h" #include "../connection.h" +#include "../connection_fwd.h" #include "../mockDatabase.h" +#include +#include +#include class MockDb : public DB::Connection { public: diff --git a/libdbpp/unittests/testConnection.cpp b/libdbpp/unittests/testConnection.cpp index 46a8e6a..66975e1 100644 --- a/libdbpp/unittests/testConnection.cpp +++ b/libdbpp/unittests/testConnection.cpp @@ -1,14 +1,15 @@ #define BOOST_TEST_MODULE DbConnection #include +#include "command.h" +#include "command_fwd.h" #include "mockdb.h" #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include BOOST_AUTO_TEST_CASE(create) diff --git a/libdbpp/unittests/testConnectionPool.cpp b/libdbpp/unittests/testConnectionPool.cpp index 5ad0121..630cb0a 100644 --- a/libdbpp/unittests/testConnectionPool.cpp +++ b/libdbpp/unittests/testConnectionPool.cpp @@ -1,9 +1,13 @@ #define BOOST_TEST_MODULE DbConnectionPool #include +#include "connection.h" +#include "mockDatabase.h" #include #include +#include #include +#include class MockPool : public DB::PluginMock, public DB::ConnectionPool { public: diff --git a/libdbpp/unittests/testMock.cpp b/libdbpp/unittests/testMock.cpp index 362b984..b2eede4 100644 --- a/libdbpp/unittests/testMock.cpp +++ b/libdbpp/unittests/testMock.cpp @@ -1,11 +1,18 @@ #define BOOST_TEST_MODULE DbMock #include -#include "../error.h" -#include "../mockDatabase.h" +#include "mockDatabase.h" #include "mockdb.h" #include +#include // for Factory::createNew, Factory::get +#include // for operator/, path #include +#include // for allocator, __shared_ptr_access +#include // for type_info + +namespace DB { + class Error; +} BOOST_AUTO_TEST_CASE(noFactory) { diff --git a/libdbpp/unittests/testParse.cpp b/libdbpp/unittests/testParse.cpp index 29ffc38..38b877d 100644 --- a/libdbpp/unittests/testParse.cpp +++ b/libdbpp/unittests/testParse.cpp @@ -1,12 +1,12 @@ #define BOOST_TEST_MODULE DbConnection #include -#include #include -#include -#include +#include #include +#include #include +#include #include using SQLs = std::vector; diff --git a/libdbpp/unittests/testPatch.cpp b/libdbpp/unittests/testPatch.cpp index cc9fd24..5febea1 100644 --- a/libdbpp/unittests/testPatch.cpp +++ b/libdbpp/unittests/testPatch.cpp @@ -1,13 +1,21 @@ #define BOOST_TEST_MODULE DbTablePatch #include +#include "command_fwd.h" +#include "mockDatabase.h" +#include "selectcommand.h" #include #include #include +#include +#include #include +#include +#include #include #include #include +#include #include class Mock : public DB::PluginMock { diff --git a/libdbpp/unittests/testUtils.cpp b/libdbpp/unittests/testUtils.cpp index 054ffb6..043fc30 100644 --- a/libdbpp/unittests/testUtils.cpp +++ b/libdbpp/unittests/testUtils.cpp @@ -1,17 +1,52 @@ #define BOOST_TEST_MODULE DbUtil #include -#include +#include "column.h" +#include "command_fwd.h" +#include "dbTypes.h" +#include "mockDatabase.h" +#include // IWYU pragma: keep #include +#include #include +#include +#include +#include #include +#include +#include #include -#include +#include +#include +#include // IWYU pragma: keep +#include +#include +#include #include +#include #include #include #include +#include +#include +#include +#include #include +#include +#include +#include +#include +// IWYU pragma: no_include + +namespace DB { + class InvalidConversion; +} +namespace DB { + class UnexpectedNullValue; +} +namespace boost::posix_time { + class time_duration; +} class StandardMockDatabase : public DB::PluginMock { public: -- cgit v1.2.3