From 0852df41eb5c319a1642c560875e99e9c31d7781 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 16 Dec 2020 15:53:50 +0000 Subject: Pass a clang-tidy check --- Jamroot.jam | 11 +++++++++-- icetray/dryice/dryice.h | 17 ++++++++++------- icetray/icetray/abstractCachingDatabaseClient.h | 8 ++++---- icetray/icetray/abstractDatabaseClient.h | 2 +- icetray/icetray/icetrayService.h | 22 ++++++++++++---------- icetray/icetray/logWriterConsole.h | 2 +- icetray/icetray/logWriterSyslog.h | 7 +++++-- icetray/icetray/logger.h | 19 +++++++++++-------- icetray/icetray/mailServer.h | 2 +- icetray/icetray/options.h | 11 +++++++---- icetray/icetray/sqlSource.h | 8 ++++++-- icetray/icetray/staticSqlSource.h | 4 ++-- icetray/icetray/stream_support.h | 1 + icetray/icetray/string_view_support.h | 2 +- icetray/tool/icetraySql.cpp | 1 + 15 files changed, 72 insertions(+), 45 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 0424a92..1bd45d9 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -18,16 +18,23 @@ project debug:on coverage:on coverage:COVERAGE - tidy:bin/mail.h - tidy:bin/logWriter.h + tidy:icetray/bin/logWriter.h + tidy:icetray/bin/mail.h + tidy:icetray/bin/mime.h + tidy:icetray/dryice/bin/tidy/debug/checker-none/cxxstd-17-iso/mockMail.h + tidy:unittests/bin/testIceTrayService.h tidy:boost-* tidy:bugprone-* + tidy:bugprone-macro-parentheses tidy:clang-* tidy:misc-* + tidy:misc-non-private-member-variables-in-classes tidy:modernize-* tidy:modernize-use-trailing-return-type + tidy:modernize-concat-nested-namespaces tidy:hicpp-* tidy:hicpp-signed-bitwise + tidy:hicpp-named-parameter tidy:performance-* tidy:ICE_IGNORE_VERSION ; diff --git a/icetray/dryice/dryice.h b/icetray/dryice/dryice.h index fb3a310..5ce38da 100644 --- a/icetray/dryice/dryice.h +++ b/icetray/dryice/dryice.h @@ -5,17 +5,18 @@ #include "icetrayService.h" #include #include +#include #include namespace IceTray { class DLL_PUBLIC DryIce : private Cube { public: - DryIce(const Ice::StringSeq & = Ice::StringSeq()); - DryIce(const DryIce &) = delete; + explicit DryIce(const Ice::StringSeq & = Ice::StringSeq()); virtual ~DryIce(); - void operator=(const DryIce &) = delete; - std::string getEndpoint() const; + SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(DryIce); + + [[nodiscard]] std::string getEndpoint() const; protected: friend class DryIceClient; @@ -40,15 +41,17 @@ namespace IceTray { DryIceClient(); virtual ~DryIceClient(); + SPECIAL_MEMBERS_DEFAULT(DryIceClient); + template - std::shared_ptr + [[nodiscard]] std::shared_ptr getProxy(const std::string & objectName) const { return Ice::checkedCast(DryIce::currentDryIce->ic->stringToProxy(objectName)); } - ServicePtr getService() const; - Ice::ObjectAdapterPtr getAdapter() const; + [[nodiscard]] ServicePtr getService() const; + [[nodiscard]] Ice::ObjectAdapterPtr getAdapter() const; private: Ice::ObjectAdapterPtr adapter; diff --git a/icetray/icetray/abstractCachingDatabaseClient.h b/icetray/icetray/abstractCachingDatabaseClient.h index 8f2e55c..b50f85f 100644 --- a/icetray/icetray/abstractCachingDatabaseClient.h +++ b/icetray/icetray/abstractCachingDatabaseClient.h @@ -9,8 +9,8 @@ namespace IceTray { class DLL_PUBLIC AbstractCachingDatabaseClient : public AbstractDatabaseClient { private: - typedef std::vector CacheKey; - typedef std::any CacheItem; + using CacheKey = std::vector; + using CacheItem = std::any; protected: explicit AbstractCachingDatabaseClient(const DB::ConnectionPoolPtr & d); @@ -28,7 +28,7 @@ namespace IceTray { return std::any_cast(*cached); } auto d(fetch(sql, params...)); - cache.add(key, CacheItem(d), time(NULL) + cacheTime); + cache.add(key, CacheItem(d), time(nullptr) + cacheTime); return d; } @@ -42,7 +42,7 @@ namespace IceTray { static void keyPushParams(CacheKey &); - typedef AdHoc::Cache Cache; + using Cache = AdHoc::Cache; Cache cache; }; } diff --git a/icetray/icetray/abstractDatabaseClient.h b/icetray/icetray/abstractDatabaseClient.h index 2a5040b..f11eb75 100644 --- a/icetray/icetray/abstractDatabaseClient.h +++ b/icetray/icetray/abstractDatabaseClient.h @@ -54,7 +54,7 @@ namespace IceTray { static void inline bind(int, DB::Command *) { } - const DB::ConnectionPoolPtr db; + DB::ConnectionPoolPtr db; }; } diff --git a/icetray/icetray/icetrayService.h b/icetray/icetray/icetrayService.h index 39e2fda..d0be7ae 100644 --- a/icetray/icetray/icetrayService.h +++ b/icetray/icetray/icetrayService.h @@ -4,6 +4,7 @@ #include "logger.h" #include "options.h" #include +#include #include #include #include @@ -12,7 +13,9 @@ namespace IceTray { class DLL_PUBLIC Service : public IceBox::Service, public AdHoc::AbstractPluginImplementation { public: Service(); - virtual ~Service(); + ~Service() override; + + SPECIAL_MEMBERS_DELETE(Service); virtual void addObjects(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr &) @@ -25,8 +28,8 @@ namespace IceTray { DB::ConnectionPoolPtr getConnectionPool( const Ice::CommunicatorPtr & ic, const std::string & type, const std::string & prefix); - static Service * getCurrent(); - static Service * create(const Ice::CommunicatorPtr &); + [[nodiscard]] static Service * getCurrent(); + [[nodiscard]] static Service * create(const Ice::CommunicatorPtr &); private: void configureLoggers(const Ice::ObjectAdapterPtr &, const Ice::PropertiesPtr &); @@ -41,29 +44,28 @@ namespace IceTray { AdHoc::PluginManager servicePlugins; }; - typedef std::shared_ptr ServicePtr; + using ServicePtr = std::shared_ptr; // Custom factory required because IceBox interface requires a naked pointer. // See: https://doc.zeroc.com/display/Ice37/Developing+IceBox+Services#DevelopingIceBoxServices-C++ServiceEntryPoint class ServiceFactory : public AdHoc::AbstractPluginImplementation { public: - virtual Service * create() const = 0; + [[nodiscard]] virtual Service * create() const = 0; template class For; }; template class ServiceFactory::For : public ServiceFactory { public: - Service * - create() const + [[nodiscard]] Service * + create() const override { return new Impl(); } }; - typedef AdHoc::Factory - PoolProvider; + using PoolProvider = AdHoc::Factory; } #endif diff --git a/icetray/icetray/logWriterConsole.h b/icetray/icetray/logWriterConsole.h index 21189ea..3dea22d 100644 --- a/icetray/icetray/logWriterConsole.h +++ b/icetray/icetray/logWriterConsole.h @@ -7,7 +7,7 @@ namespace IceTray { namespace Logging { class ConsoleLogWriter : public AbstractLogWriter { public: - ConsoleLogWriter(const Ice::PropertiesPtr & p); + explicit ConsoleLogWriter(const Ice::PropertiesPtr & p); void message(LogLevel priority, Domain domain, std::string_view message, const Ice::Current &) override; diff --git a/icetray/icetray/logWriterSyslog.h b/icetray/icetray/logWriterSyslog.h index 88488bd..c557281 100644 --- a/icetray/icetray/logWriterSyslog.h +++ b/icetray/icetray/logWriterSyslog.h @@ -2,13 +2,16 @@ #define ICETRAY_LOGGING_SYSLOG_H #include "logger.h" +#include namespace IceTray { namespace Logging { class SyslogLogWriter : public AbstractLogWriter { public: - SyslogLogWriter(const Ice::PropertiesPtr & p); - ~SyslogLogWriter(); + explicit SyslogLogWriter(const Ice::PropertiesPtr & p); + ~SyslogLogWriter() override; + + SPECIAL_MEMBERS_DELETE(SyslogLogWriter); void message(LogLevel priority, Domain domain, std::string_view message, const Ice::Current &) override; diff --git a/icetray/icetray/logger.h b/icetray/icetray/logger.h index 2f4ba44..44bbc98 100644 --- a/icetray/icetray/logger.h +++ b/icetray/icetray/logger.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -17,15 +18,17 @@ namespace IceTray { class LogManager; class LoggerBase; - typedef std::set LogWriters; - typedef std::array LogLevelWriters; - typedef std::set Loggers; + using LogWriters = std::set; + using LogLevelWriters = std::array; + using Loggers = std::set; class DLL_PUBLIC LoggerBase { public: - LoggerBase(Domain domain); + explicit LoggerBase(Domain domain); virtual ~LoggerBase() = 0; + SPECIAL_MEMBERS_DELETE(LoggerBase); + const Domain & getDomain() const; protected: @@ -37,7 +40,7 @@ namespace IceTray { class DLL_PUBLIC Logger : public LoggerBase { public: - Logger(const Domain & domain); + explicit Logger(const Domain & domain); void message(LogLevel priority, const std::string & msg) const; void messagef(LogLevel priority, const char * msgfmt, ...) const __attribute__((format(printf, 3, 4))); @@ -76,7 +79,7 @@ namespace IceTray { LogLevelWriters::const_iterator firstFor(LogLevel priority) const; }; - typedef std::shared_ptr LoggerPtr; + using LoggerPtr = std::shared_ptr; class DLL_PUBLIC LogManager { public: @@ -111,7 +114,7 @@ namespace IceTray { explicit AbstractLogWriter(LogLevel level); explicit AbstractLogWriter(const std::string & prefix, const Ice::PropertiesPtr & p); - typedef std::map LogDomains; + using LogDomains = std::map; LogDomains logDomains; public: @@ -119,7 +122,7 @@ namespace IceTray { static void writeDomain(std::ostream &, ssize_t, const Domain &); }; - typedef AdHoc::Factory LogWriterFactory; + using LogWriterFactory = AdHoc::Factory; } } diff --git a/icetray/icetray/mailServer.h b/icetray/icetray/mailServer.h index e389323..a77dd46 100644 --- a/icetray/icetray/mailServer.h +++ b/icetray/icetray/mailServer.h @@ -14,7 +14,7 @@ namespace IceTray { class DLL_PUBLIC LibesmtpMailServer : public MailServer, BasicMailServer { public: - LibesmtpMailServer(std::string server); + explicit LibesmtpMailServer(std::string server); void sendEmail(const EmailPtr & msg) override; diff --git a/icetray/icetray/options.h b/icetray/icetray/options.h index c8cbba2..34d20c2 100644 --- a/icetray/icetray/options.h +++ b/icetray/icetray/options.h @@ -3,14 +3,15 @@ #include #include +#include #include #include namespace IceTray { - typedef std::shared_ptr OptionsDescPtr; + using OptionsDescPtr = std::shared_ptr; class DLL_PUBLIC Options : public AdHoc::AbstractPluginImplementation { public: - Options(std::string name); + explicit Options(std::string name); private: friend class OptionsCollation; @@ -18,8 +19,8 @@ namespace IceTray { OptionsDescPtr getOptions(); const std::string optionsName; }; - typedef AdHoc::Factory OptionsFactory; - typedef AdHoc::PluginOf OptionsPlugin; + using OptionsFactory = AdHoc::Factory; + using OptionsPlugin = AdHoc::PluginOf; template class DLL_PUBLIC OptionsResolver { public: @@ -44,6 +45,8 @@ namespace IceTray { OptionsCollation(); ~OptionsCollation(); + SPECIAL_MEMBERS_DELETE(OptionsCollation); + void apply(const Ice::PropertiesPtr & p); std::ostream & write(std::ostream &) const; diff --git a/icetray/icetray/sqlSource.h b/icetray/icetray/sqlSource.h index 5efb9e1..eb428dc 100644 --- a/icetray/icetray/sqlSource.h +++ b/icetray/icetray/sqlSource.h @@ -1,6 +1,7 @@ #ifndef ICETRAY_SQLSOURCE_H #define ICETRAY_SQLSOURCE_H +#include #include #include #include @@ -9,10 +10,13 @@ namespace IceTray { class DLL_PUBLIC SqlSource { public: + SqlSource() = default; virtual ~SqlSource() = default; - virtual const std::string & getSql() const = 0; - virtual DB::CommandOptionsCPtr getCommandOptions() const = 0; + SPECIAL_MEMBERS_DELETE(SqlSource); + + [[nodiscard]] virtual const std::string & getSql() const = 0; + [[nodiscard]] virtual DB::CommandOptionsCPtr getCommandOptions() const = 0; DB::ModifyCommandPtr modify(DB::Connection * db) const; DB::SelectCommandPtr select(DB::Connection * db) const; diff --git a/icetray/icetray/staticSqlSource.h b/icetray/icetray/staticSqlSource.h index fc5fe76..b64b86d 100644 --- a/icetray/icetray/staticSqlSource.h +++ b/icetray/icetray/staticSqlSource.h @@ -9,8 +9,8 @@ namespace IceTray { explicit StaticSqlSource(std::string sql); StaticSqlSource(std::string sql, const std::string & optsName, const DB::CommandOptionsMap &); - const std::string & getSql() const override; - DB::CommandOptionsCPtr getCommandOptions() const override; + [[nodiscard]] const std::string & getSql() const override; + [[nodiscard]] DB::CommandOptionsCPtr getCommandOptions() const override; protected: const std::string sql; diff --git a/icetray/icetray/stream_support.h b/icetray/icetray/stream_support.h index 8367588..fa32a31 100644 --- a/icetray/icetray/stream_support.h +++ b/icetray/icetray/stream_support.h @@ -7,6 +7,7 @@ namespace IceTray { class StreamPtr { public: + // NOLINTNEXTLINE(hicpp-explicit-conversions) operator FILE *() const { return f; diff --git a/icetray/icetray/string_view_support.h b/icetray/icetray/string_view_support.h index 71bfcae..12d8077 100644 --- a/icetray/icetray/string_view_support.h +++ b/icetray/icetray/string_view_support.h @@ -24,7 +24,7 @@ namespace Ice { static inline void read(S * stream, std::string_view & v) { - const char * vdata = 0; + const char * vdata = nullptr; size_t vsize = 0; stream->read(vdata, vsize); diff --git a/icetray/tool/icetraySql.cpp b/icetray/tool/icetraySql.cpp index 924d1ea..521a2f0 100644 --- a/icetray/tool/icetraySql.cpp +++ b/icetray/tool/icetraySql.cpp @@ -63,6 +63,7 @@ main(int argc, char ** argv) po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(opts).positional(p).run(), vm); + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) if (vm.count("help")) { std::cout << opts << std::endl; return 1; -- cgit v1.2.3