From 064a44e571f2bf2593571fc42f808129f8c447c5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 27 Jun 2020 16:23:18 +0100 Subject: Pass clang-tidy and cppcheck --- Jamroot.jam | 33 ++++++++++++++++++--------------- slicer/db/sqlInsertSerializer.h | 11 ++++++----- slicer/db/sqlSelectDeserializer.h | 3 ++- slicer/db/sqlSource.h | 2 +- slicer/ice/serializer.cpp | 8 ++++---- slicer/ice/serializer.h | 12 ++++++------ slicer/slicer/modelPartsTypes.h | 3 --- slicer/slicer/modelPartsTypes.impl.h | 19 +++++++++++-------- slicer/test/preprocessor.cpp | 11 ++++++----- slicer/tool/parser.cpp | 10 +++++----- 10 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 9d1aa16..b350916 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -34,22 +34,25 @@ project tidy:hicpp-no-array-decay tidy:hicpp-vararg tidy:performance-* - tidy:test/bin/tidy/debug/cxxstd-17-iso/classes.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/classtype.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/collections.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/enums.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/inheritance.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/interfaces.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/json.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/locals.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/optionals.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/structs.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/types.h - tidy:test/bin/tidy/debug/cxxstd-17-iso/xml.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/classes.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/classtype.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/collections.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/enums.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/inheritance.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/interfaces.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/json.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/locals.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/optionals.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/structs.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/types.h + tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/xml.h tidy:slicer/bin/common.h - tidy:xml/bin/tidy/debug/cxxstd-17-iso/xmlExceptions.h - tidy:db/bin/tidy/debug/cxxstd-17-iso/sqlExceptions.h - tidy:db/bin/tidy/debug/cxxstd-17-iso/testModels.h + tidy:xml/bin/tidy/debug/checker-none/cxxstd-17-iso/xmlExceptions.h + tidy:db/bin/tidy/debug/checker-none/cxxstd-17-iso/sqlExceptions.h + tidy:db/bin/tidy/debug/checker-none/cxxstd-17-iso/testModels.h + tidy:ice/cpp/* + tidy:ICE_IGNORE_VERSION + tidy:__x86_64 ; build-project slicer ; diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index 6150d66..b964b5e 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -29,21 +29,22 @@ namespace Slicer { class DLL_PUBLIC SqlAutoIdInsertSerializer : public SqlInsertSerializer { public: - template SqlAutoIdInsertSerializer(const P &... p) : SqlInsertSerializer(p...) { } + template explicit SqlAutoIdInsertSerializer(const P &... p) : SqlInsertSerializer(p...) { } protected: virtual void createInsertField( - int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; + int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const override; virtual void bindObjectAndExecuteField( - int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; + int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const override; }; class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer { public: - template SqlFetchIdInsertSerializer(const P &... p) : SqlAutoIdInsertSerializer(p...) { } + template + explicit SqlFetchIdInsertSerializer(const P &... p) : SqlAutoIdInsertSerializer(p...) { } protected: - virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; + virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const override; }; } diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h index 5f34ef4..32961e9 100644 --- a/slicer/db/sqlSelectDeserializer.h +++ b/slicer/db/sqlSelectDeserializer.h @@ -8,7 +8,8 @@ namespace Slicer { class DLL_PUBLIC SqlSelectDeserializer : public Slicer::Deserializer { public: - SqlSelectDeserializer(DB::SelectCommand *, Ice::optional typeIdCol = Ice::optional()); + explicit SqlSelectDeserializer( + DB::SelectCommand *, Ice::optional typeIdCol = Ice::optional()); void Deserialize(Slicer::ModelPartForRootPtr) override; diff --git a/slicer/db/sqlSource.h b/slicer/db/sqlSource.h index 548f35e..c48fb4d 100644 --- a/slicer/db/sqlSource.h +++ b/slicer/db/sqlSource.h @@ -11,7 +11,7 @@ namespace Slicer { public Slicer::TValueSource, public Slicer::TValueSource { public: - SqlSource(const DB::Column & c); + explicit SqlSource(const DB::Column & c); bool isNull() const; void set(boost::posix_time::ptime & b) const override; diff --git a/slicer/ice/serializer.cpp b/slicer/ice/serializer.cpp index 877f531..a7a4eb9 100644 --- a/slicer/ice/serializer.cpp +++ b/slicer/ice/serializer.cpp @@ -14,14 +14,14 @@ namespace Slicer { { ic->destroy(); } - IceBlobSerializer::IceBlobSerializer(Ice::ByteSeq & b) : blob(b) { } + IceBlobSerializer::IceBlobSerializer(Ice::ByteSeq & b) : refblob(b) { } void IceBlobSerializer::Serialize(ModelPartForRootPtr mp) { Ice::OutputStream s(ic); mp->Write(s); - s.finished(blob); + s.finished(refblob); } IceStreamSerializer::IceStreamSerializer(std::ostream & os) : IceBlobSerializer(blob), strm(os) { } @@ -33,12 +33,12 @@ namespace Slicer { strm.write((const char *)&blob.front(), blob.size()); } - IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : blob(b) { } + IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : refblob(b) { } void IceBlobDeserializer::Deserialize(ModelPartForRootPtr mp) { - Ice::InputStream s(ic, blob); + Ice::InputStream s(ic, refblob); mp->Read(s); } diff --git a/slicer/ice/serializer.h b/slicer/ice/serializer.h index 05a7752..cbead6f 100644 --- a/slicer/ice/serializer.h +++ b/slicer/ice/serializer.h @@ -19,17 +19,17 @@ namespace Slicer { class DLL_PUBLIC IceBlobSerializer : public Serializer, protected IceBase { public: - IceBlobSerializer(Ice::ByteSeq &); + explicit IceBlobSerializer(Ice::ByteSeq &); void Serialize(ModelPartForRootPtr) override; private: - Ice::ByteSeq & blob; + Ice::ByteSeq & refblob; }; class DLL_PUBLIC IceStreamSerializer : public IceBlobSerializer { public: - IceStreamSerializer(std::ostream &); + explicit IceStreamSerializer(std::ostream &); void Serialize(ModelPartForRootPtr) override; @@ -40,17 +40,17 @@ namespace Slicer { class DLL_PUBLIC IceBlobDeserializer : public Deserializer, protected IceBase { public: - IceBlobDeserializer(const Ice::ByteSeq &); + explicit IceBlobDeserializer(const Ice::ByteSeq &); void Deserialize(ModelPartForRootPtr) override; protected: - const Ice::ByteSeq & blob; + const Ice::ByteSeq & refblob; }; class DLL_PUBLIC IceStreamDeserializer : public IceBlobDeserializer { public: - IceStreamDeserializer(std::istream &); + explicit IceStreamDeserializer(std::istream &); void Deserialize(ModelPartForRootPtr) override; diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index b47353b..78eee3b 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -361,9 +361,6 @@ namespace Slicer { explicit ModelPartForStreamRoot(Stream * s); const std::string & GetRootName() const override; - - private: - Stream * stream; }; } diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index be464d1..ca562a6 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -447,11 +447,13 @@ namespace Slicer { ChildRef ModelPartForComplex::GetChildRefFromRange(const R & range, const HookFilter & flt) { - auto model = GetModel(); - for (const auto & h : range) { - if (h->filter(flt)) { - return ChildRef(h->Get(model), h->GetMetadata()); - } + const auto itr = std::find_if(boost::begin(range), boost::end(range), [&flt](auto && h) { + return h->filter(flt); + }); + if (itr != boost::end(range)) { + const auto & h = *itr; + auto model = GetModel(); + return ChildRef(h->Get(model), h->GetMetadata()); } return ChildRef(); } @@ -526,17 +528,18 @@ namespace Slicer { class DLL_PRIVATE ModelPartForComplex::HookMetadata : public ModelPartForComplex::template Hook { public: HookMetadata(MT T::*member, const std::string & n, Metadata md) : - Hook(member, n), metadata(std::move(md)) + Hook(member, n), hookMetadata(std::move(md)) { } [[nodiscard]] const Metadata & GetMetadata() const override { - return metadata; + return hookMetadata; } - const Metadata metadata; + private: + const Metadata hookMetadata; }; // ModelPartForClass diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index 454d58a..4f474ee 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using ComponentsCount = std::map; @@ -16,12 +17,12 @@ ComponentsCount COMPONENTS_IN_TEST_ICE = {{"classtype.ice", 1}, {"classes.ice", unsigned int total() { - unsigned int t = 0; - for (const auto & c : COMPONENTS_IN_TEST_ICE) { - t += c.second; - } + const auto t = std::accumulate( + COMPONENTS_IN_TEST_ICE.begin(), COMPONENTS_IN_TEST_ICE.end(), 0U, [](auto & t, auto && c) { + return t += c.second; + }); + BOOST_CHECK_EQUAL(47, t); return t; - BOOST_REQUIRE_EQUAL(40, t); } void diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index d342c35..81bb10e 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -595,9 +595,9 @@ namespace Slicer { cpp = cppfile.get(); Slicer::Slicer::Args args; // Copy includes to args - for (const auto & include : includes) { - args.push_back("-I" + include.string()); - } + std::transform(includes.begin(), includes.end(), std::back_inserter(args), [](auto && include) { + return "-I" + include.string(); + }); Slice::PreprocessorPtr icecpp = Slice::Preprocessor::create("slicer", slicePath, args); FILE * cppHandle = icecpp->preprocess(false); @@ -618,7 +618,7 @@ namespace Slicer { throw CompilerError("unit parse failed"); } - unsigned int initial = Components(); + unsigned int initial = components; u->visit(this, false); @@ -628,7 +628,7 @@ namespace Slicer { cpp = nullptr; } - return Components() - initial; + return components - initial; } catch (...) { if (!cppPath.empty()) { -- cgit v1.2.3