From fed7bd938e71b1037b2e6eba2d2017f7fa1d7011 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Nov 2020 11:27:56 +0000 Subject: Pass clang-tidy and cppcheck --- Jamroot.jam | 2 + slicer/slicer/enum-test.cpp | 36 ++++++++-------- slicer/slicer/enumMap.h | 8 ++-- slicer/slicer/hook-test.cpp | 93 +++++++++++++++++++++-------------------- slicer/slicer/hookMap.h | 29 ++++++------- slicer/slicer/metadata-test.cpp | 26 ++++++------ slicer/slicer/metadata.h | 17 ++++---- slicer/slicer/modelParts.h | 2 +- slicer/tool/icemetadata.cpp | 1 - slicer/tool/icemetadata.h | 11 ++--- slicer/tool/parser.cpp | 5 ++- slicer/tool/parser.h | 7 ++-- 12 files changed, 124 insertions(+), 113 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index b878832..292cefc 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -28,11 +28,13 @@ project tidy:clang-analyzer-cplusplus.NewDeleteLeaks tidy:misc-* tidy:misc-non-private-member-variables-in-classes + tidy:misc-no-recursion tidy:modernize-* tidy:modernize-use-trailing-return-type tidy:hicpp-* tidy:hicpp-no-array-decay tidy:hicpp-vararg + tidy:hicpp-named-parameter tidy:performance-* tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/classes.h tidy:test/bin/tidy/debug/checker-none/cxxstd-17-iso/classtype.h diff --git a/slicer/slicer/enum-test.cpp b/slicer/slicer/enum-test.cpp index 166804f..43e191a 100644 --- a/slicer/slicer/enum-test.cpp +++ b/slicer/slicer/enum-test.cpp @@ -1,22 +1,24 @@ #include "enumMap.h" -enum class Es { one, two, three }; -const std::string one {"one"}, two {"two"}, three {"three"}; +namespace test { + enum class Es { one, two, three }; + const std::string one {"one"}, two {"two"}, three {"three"}; -constexpr Slicer::EnumMapImpl em {{{ - {Es::one, "one", &one}, - {Es::two, "two", &two}, - {Es::three, "three", &three}, -}}}; + constexpr Slicer::EnumMapImpl em {{{ + {Es::one, "one", &one}, + {Es::two, "two", &two}, + {Es::three, "three", &three}, + }}}; -static_assert(em.arr.size() == 3); -static_assert(em.arr[0].value == Es::one); -static_assert(em.arr[1].name == "two"); -static_assert(em.arr[1].nameStr == &two); -static_assert(em.arr[2].value == Es::three); + static_assert(em.arr.size() == 3); + static_assert(em.arr[0].value == Es::one); + static_assert(em.arr[1].name == "two"); + static_assert(em.arr[1].nameStr == &two); + static_assert(em.arr[2].value == Es::three); -static_assert(em.find("one")->value == Es::one); -static_assert(em.find("three")->value == Es::three); -static_assert(em.find(Es::one)->name == "one"); -static_assert(em.find(Es::three)->name == "three"); -static_assert(!em.find("four")); + static_assert(em.find("one")->value == Es::one); + static_assert(em.find("three")->value == Es::three); + static_assert(em.find(Es::one)->name == "one"); + static_assert(em.find(Es::three)->name == "three"); + static_assert(!em.find("four")); +} diff --git a/slicer/slicer/enumMap.h b/slicer/slicer/enumMap.h index a6f941d..8f63819 100644 --- a/slicer/slicer/enumMap.h +++ b/slicer/slicer/enumMap.h @@ -14,9 +14,9 @@ namespace Slicer { template class EnumMap { public: struct Node { - E value; - std::string_view name; - const std::string * nameStr; + E value {}; + std::string_view name {}; + const std::string * nameStr {}; }; template @@ -48,7 +48,7 @@ namespace Slicer { using NodeType = typename EnumMap::Node; template using Arr = std::array; - inline constexpr EnumMapImpl(Arr a) : arr(std::move(a)) + inline constexpr explicit EnumMapImpl(Arr a) : arr(std::move(a)) { EnumMap::begin = arr.begin(); EnumMap::end = arr.end(); diff --git a/slicer/slicer/hook-test.cpp b/slicer/slicer/hook-test.cpp index d478beb..abde1c5 100644 --- a/slicer/slicer/hook-test.cpp +++ b/slicer/slicer/hook-test.cpp @@ -3,53 +3,56 @@ #include -struct S { - int aa; - int aA; - int Aa; - int AA; - std::string b; -}; -const std::string aa {"aa"}, aA {"aA"}, Aa {"Aa"}, AA {"AA"}, b {"b"}; +namespace test { + struct S { + S(); + int aa; + int aA; + int Aa; + int AA; + std::string b; + }; + const std::string aa {"aa"}, aA {"aA"}, Aa {"Aa"}, AA {"AA"}, b {"b"}; -using C = Slicer::ModelPartForComplex; -constexpr C::Hook, 0> haa {&S::aa, "aa", "aa", &aa}; -constexpr C::Hook, 1> haA {&S::aA, "aA", "aa", &aA, "md1"}; -constexpr C::Hook, 3> hAa {&S::Aa, "Aa", "aa", &Aa, "md2", "md3", "md4"}; -constexpr C::Hook> hAA {&S::AA, "AA", "aa", &AA}; -constexpr C::Hook, 0> hb {&S::b, "b", "b", &b}; -constexpr Slicer::HooksImpl h {{{&haa, &haA, &hAa, &hAA, &hb}}}; + using C = Slicer::ModelPartForComplex; + constexpr C::Hook, 0> haa {&S::aa, "aa", "aa", &aa}; + constexpr C::Hook, 1> haA {&S::aA, "aA", "aa", &aA, "md1"}; + constexpr C::Hook, 3> hAa {&S::Aa, "Aa", "aa", &Aa, "md2", "md3", "md4"}; + constexpr C::Hook> hAA {&S::AA, "AA", "aa", &AA}; + constexpr C::Hook, 0> hb {&S::b, "b", "b", &b}; + constexpr Slicer::HooksImpl h {{{&haa, &haA, &hAa, &hAA, &hb}}}; -static_assert(h.arr.size() == 5); -static_assert(h.arr[0]->name == "aa"); -static_assert(h.arr[0]->nameLower == "aa"); -static_assert(h.arr[0]->nameStr == &aa); -static_assert(h.arr[1]->name == "aA"); -static_assert(h.arr[1]->nameLower == "aa"); -static_assert(h.arr[1]->nameStr == &aA); -static_assert(h.arr[4]->name == "b"); -static_assert(h.arr[4]->nameLower == "b"); -static_assert(h.arr[4]->nameStr == &b); + static_assert(h.arr.size() == 5); + static_assert(h.arr[0]->name == "aa"); + static_assert(h.arr[0]->nameLower == "aa"); + static_assert(h.arr[0]->nameStr == &aa); + static_assert(h.arr[1]->name == "aA"); + static_assert(h.arr[1]->nameLower == "aa"); + static_assert(h.arr[1]->nameStr == &aA); + static_assert(h.arr[4]->name == "b"); + static_assert(h.arr[4]->nameLower == "b"); + static_assert(h.arr[4]->nameStr == &b); -constexpr auto aas = h.equal_range("aa"); -constexpr auto bbs = h.equal_range("bb"); -static_assert(aas.begin() != aas.end()); -static_assert(bbs.begin() == bbs.end()); -static_assert(aas.begin()->name == "aa"); + constexpr auto aas = h.equal_range("aa"); + constexpr auto bbs = h.equal_range("bb"); + static_assert(aas.begin() != aas.end()); + static_assert(bbs.begin() == bbs.end()); + static_assert(aas.begin()->name == "aa"); -constexpr auto aa0 = aas.begin(); -static_assert(aa0->name == "aa"); -constexpr auto aa1 = aa0 + 1; -static_assert(aa1 == aas.end()); -static_assert(std::distance(aas.begin(), aas.end()) == 1); -static_assert(std::distance(bbs.begin(), bbs.end()) == 0); + constexpr auto aa0 = aas.begin(); + static_assert(aa0->name == "aa"); + constexpr auto aa1 = aa0 + 1; + static_assert(aa1 == aas.end()); + static_assert(std::distance(aas.begin(), aas.end()) == 1); + static_assert(std::distance(bbs.begin(), bbs.end()) == 0); -constexpr auto laas = h.equal_range_lower("aa"); -constexpr auto lAAs = h.equal_range_lower("AA"); -static_assert(std::distance(laas.begin(), laas.end()) == 4); -static_assert(std::distance(lAAs.begin(), lAAs.end()) == 0); -static_assert(laas.begin()->name == "aa"); -static_assert((laas.begin() + 1)->name == "aA"); -static_assert((laas.begin() + 2)->name == "Aa"); -static_assert((laas.begin() + 3)->name == "AA"); -static_assert((laas.begin() + 4) == laas.end()); + constexpr auto laas = h.equal_range_lower("aa"); + constexpr auto lAAs = h.equal_range_lower("AA"); + static_assert(std::distance(laas.begin(), laas.end()) == 4); + static_assert(std::distance(lAAs.begin(), lAAs.end()) == 0); + static_assert(laas.begin()->name == "aa"); + static_assert((laas.begin() + 1)->name == "aA"); + static_assert((laas.begin() + 2)->name == "Aa"); + static_assert((laas.begin() + 3)->name == "AA"); + static_assert((laas.begin() + 4) == laas.end()); +} diff --git a/slicer/slicer/hookMap.h b/slicer/slicer/hookMap.h index 8eba5f5..a362a18 100644 --- a/slicer/slicer/hookMap.h +++ b/slicer/slicer/hookMap.h @@ -15,18 +15,18 @@ namespace Slicer { template class iter : public std::iterator { public: - constexpr inline iter(const eq * const r, const HookPtr * c) : range(r), cur(c) + [[nodiscard]] constexpr inline iter(const eq * const r, const HookPtr * c) : range(r), cur(c) { moveMatch(); } - constexpr inline HookPtr + [[nodiscard]] constexpr inline HookPtr operator*() const { return *cur; } - constexpr inline HookPtr + [[nodiscard]] constexpr inline HookPtr operator->() const { return *cur; @@ -40,7 +40,7 @@ namespace Slicer { } } - constexpr inline iter + [[nodiscard]] constexpr inline iter operator+(std::size_t n) const { auto i {*this}; @@ -50,13 +50,13 @@ namespace Slicer { return i; } - constexpr inline bool + [[nodiscard]] constexpr inline bool operator!=(const iter & other) const { return cur != other.cur; } - constexpr inline bool + [[nodiscard]] constexpr inline bool operator==(const iter & other) const { return cur == other.cur; @@ -77,13 +77,13 @@ namespace Slicer { template class eq { public: - constexpr inline iter + [[nodiscard]] constexpr inline iter begin() const { return {this, b}; } - constexpr inline iter + [[nodiscard]] constexpr inline iter end() const { return {this, e}; @@ -95,21 +95,21 @@ namespace Slicer { }; template - constexpr inline eq + [[nodiscard]] constexpr inline eq equal_range(K && k) const { return {std::forward(k), &HookCommon::name, _begin, _end}; } template - constexpr inline eq + [[nodiscard]] constexpr inline eq equal_range_lower(K && k) const { return {std::forward(k), &HookCommon::nameLower, _begin, _end}; } template - inline auto + [[nodiscard]] inline auto equal_range_nocase(const K & k) const { std::string i {k}; @@ -117,12 +117,13 @@ namespace Slicer { return equal_range_lower(std::move(i)); } - constexpr inline auto + [[nodiscard]] constexpr inline auto begin() const { return _begin; } - constexpr inline auto + + [[nodiscard]] constexpr inline auto end() const { return _end; @@ -138,7 +139,7 @@ namespace Slicer { using HookPtr = typename Hooks::HookPtr; template using Arr = std::array; - inline constexpr HooksImpl(Arr a) : arr(std::move(a)) + inline constexpr explicit HooksImpl(Arr a) : arr(std::move(a)) { Hooks::_begin = arr.begin(); Hooks::_end = arr.end(); diff --git a/slicer/slicer/metadata-test.cpp b/slicer/slicer/metadata-test.cpp index 2d3215a..a2cd6ec 100644 --- a/slicer/slicer/metadata-test.cpp +++ b/slicer/slicer/metadata-test.cpp @@ -1,15 +1,17 @@ #include "metadata.h" -constexpr Slicer::MetaDataImpl<4> md {{{ - "slicer:yes", - "slicer:no", - "slicer:sub:scope", - "notslicer:dontcare", -}}}; +namespace test { + constexpr Slicer::MetaDataImpl<4> md {{{ + "slicer:yes", + "slicer:no", + "slicer:sub:scope", + "notslicer:dontcare", + }}}; -static_assert(md.flagSet("slicer:yes")); -static_assert(md.flagSet("slicer:no")); -static_assert(md.flagNotSet("slicer:chickens")); -static_assert(md.value("slicer:").has_value()); -static_assert(md.value("slicer:").value() == "yes"); -static_assert(!md.value("nope:").has_value()); + static_assert(md.flagSet("slicer:yes")); + static_assert(md.flagSet("slicer:no")); + static_assert(md.flagNotSet("slicer:chickens")); + static_assert(md.value("slicer:").has_value()); + static_assert(md.value("slicer:").value() == "yes"); + static_assert(!md.value("nope:").has_value()); +} diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h index ced234f..5ca3781 100644 --- a/slicer/slicer/metadata.h +++ b/slicer/slicer/metadata.h @@ -16,20 +16,20 @@ namespace Slicer { constexpr MetaData() = default; // Flags - constexpr inline bool + [[nodiscard]] constexpr inline bool flagSet(std::string_view flag) const { return find(flag) != _end; } - constexpr inline bool + [[nodiscard]] constexpr inline bool flagNotSet(std::string_view flag) const { return find(flag) == _end; } // Values - constexpr std::optional + [[nodiscard]] constexpr std::optional value(std::string_view prefix) const { for (auto mditr = _begin; mditr != _end; mditr++) { @@ -41,7 +41,7 @@ namespace Slicer { return {}; } - std::vector + [[nodiscard]] std::vector values(std::string_view prefix) const { std::vector mds; @@ -54,12 +54,13 @@ namespace Slicer { return mds; } - constexpr auto + [[nodiscard]] constexpr auto begin() const { return _begin; } - constexpr auto + + [[nodiscard]] constexpr auto end() const { return _end; @@ -69,7 +70,7 @@ namespace Slicer { Iter _begin {}; Iter _end {}; - constexpr Iter + [[nodiscard]] constexpr Iter find(Value v) const { for (auto mdptr = _begin; mdptr != _end; mdptr++) { @@ -84,7 +85,7 @@ namespace Slicer { template class DLL_PUBLIC MetaDataImpl : public MetaData<> { public: using Arr = std::array; - constexpr inline MetaDataImpl(Arr a) : arr(std::move(a)) + constexpr inline explicit MetaDataImpl(Arr a) : arr(std::move(a)) { _begin = arr.begin(); _end = arr.end(); diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 6af9344..6b283a4 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -112,7 +112,7 @@ namespace Slicer { { } - bool filter(const HookFilter & flt) const; + [[nodiscard]] bool filter(const HookFilter & flt) const; void apply(const ChildHandler & ch, const ModelPartPtr & modelPart) const; [[nodiscard]] virtual const Metadata & GetMetadata() const = 0; diff --git a/slicer/tool/icemetadata.cpp b/slicer/tool/icemetadata.cpp index 422b17e..60bd5a3 100644 --- a/slicer/tool/icemetadata.cpp +++ b/slicer/tool/icemetadata.cpp @@ -2,7 +2,6 @@ #include namespace Slicer { - IceMetaData::IceMetaData() { } IceMetaData::IceMetaData(Slice::StringList && a) : arr {std::forward(a)} { _begin = arr.begin(); diff --git a/slicer/tool/icemetadata.h b/slicer/tool/icemetadata.h index 90bfe5e..07d4db2 100644 --- a/slicer/tool/icemetadata.h +++ b/slicer/tool/icemetadata.h @@ -11,22 +11,23 @@ namespace Slicer { public: static constexpr std::string_view slicer_prefix {"slicer:"}; - explicit IceMetaData(); + explicit IceMetaData() = default; explicit IceMetaData(Slice::StringList && arr); + ~IceMetaData() = default; SPECIAL_MEMBERS_DELETE(IceMetaData); [[nodiscard]] static std::vector split(std::string_view metaData); - bool hasSlicerMetaData() const; - size_t countSlicerMetaData() const; + [[nodiscard]] bool hasSlicerMetaData() const; + [[nodiscard]] size_t countSlicerMetaData() const; - constexpr bool static isSlicerMetaData(std::string_view md) + [[nodiscard]] constexpr bool static isSlicerMetaData(std::string_view md) { return md.substr(0, slicer_prefix.length()) == slicer_prefix; } - auto + [[nodiscard]] auto getSlicerMetaData() const { return values(slicer_prefix); diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 98a41e7..e1cc988 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -417,7 +417,7 @@ namespace Slicer { fprintbf(cpp, " %s, ", Slice::typeToString(type, dm->optional())); createNewModelPartPtrFor(type, dm, md); fprintbf(cpp, ", %d", md.countSlicerMetaData()); - fprintbf(cpp, " > hook_C%d_%s {&%s, \"%s\", \"%s\", &hstr_C%d_%s", components, name, dm->scoped(), name, + fprintbf(cpp, R"( > hook_C%d_%s {&%s, "%s", "%s", &hstr_C%d_%s)", components, name, dm->scoped(), name, lname, components, name); if (md.hasSlicerMetaData()) { fprintbf(cpp, ","); @@ -669,7 +669,8 @@ namespace Slicer { if (split.size() < 3) { throw CompilerError("conversion needs at least 3 parts type:toModelFunc:toExchangeFunc[:options]"); } - rtn.push_back(ConversionSpec {split[0], split[1], split[2], {&split[3], &split[split.size()]}}); + rtn.push_back(ConversionSpec { + CppName {split[0]}, CppName {split[1]}, CppName {split[2]}, {split.begin() + 3, split.end()}}); } return rtn; } diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h index 7ba1b79..4335d1d 100644 --- a/slicer/tool/parser.h +++ b/slicer/tool/parser.h @@ -14,18 +14,17 @@ namespace Slicer { }; struct CppName : public SplitString { - inline CppName(std::string_view in) : SplitString {in, "."} { } + explicit inline CppName(std::string_view in) : SplitString {in, "."} { } }; class DLL_PUBLIC Slicer : public Slice::ParserVisitor { public: struct Args : public SplitString { - inline Args(std::string_view in) : SplitString {in, ","} { } + explicit inline Args(std::string_view in) : SplitString {in, ","} { } using SplitString::SplitString; }; - class ConversionSpec { - public: + struct ConversionSpec { CppName ExchangeType; CppName ConvertToModelFunc; CppName ConvertToExchangeFunc; -- cgit v1.2.3