From 781269fe3e20ebbfa2cf6c2b1aaae3bd7dc3d8e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 23 Sep 2021 19:12:28 +0100 Subject: Remove unnecessary casts --- Jamroot.jam | 1 + slicer/json/testSpecifics.cpp | 20 ++++++++------------ slicer/tool/parser.cpp | 17 +++++++++-------- slicer/xml/serializer.cpp | 7 +++++++ slicer/xml/serializer.h | 7 +++++++ slicer/xml/testSpecifics.cpp | 8 ++++---- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 0e0b273..1ef5751 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -19,6 +19,7 @@ project debug:on debug:-Wnon-virtual-dtor debug:-Woverloaded-virtual + gcc,debug:-Wuseless-cast coverage:on tidy:boost-* tidy:bugprone-* diff --git a/slicer/json/testSpecifics.cpp b/slicer/json/testSpecifics.cpp index 6bfc9d4..ba85e5e 100644 --- a/slicer/json/testSpecifics.cpp +++ b/slicer/json/testSpecifics.cpp @@ -6,16 +6,12 @@ BOOST_AUTO_TEST_CASE(factories) { - BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".json", "/some.json"))); - BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".json", "/some.json"))); - BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".js", "/some.js"))); - BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".js", "/some.js"))); - BOOST_REQUIRE( - Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); - BOOST_REQUIRE( - Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin))); - BOOST_REQUIRE( - Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); - BOOST_REQUIRE( - Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin))); + BOOST_REQUIRE(Slicer::FileSerializerFactory::createNew(".json", "/some.json")); + BOOST_REQUIRE(Slicer::FileDeserializerFactory::createNew(".json", "/some.json")); + BOOST_REQUIRE(Slicer::FileSerializerFactory::createNew(".js", "/some.js")); + BOOST_REQUIRE(Slicer::FileDeserializerFactory::createNew(".js", "/some.js")); + BOOST_REQUIRE(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout)); + BOOST_REQUIRE(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin)); + BOOST_REQUIRE(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout)); + BOOST_REQUIRE(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin)); } diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 0d83653..e6a7432 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -204,7 +204,7 @@ namespace Slicer { ForwardDeclare fd {cpp, count}; u->visit(&fd, true); - fprintbf(cpp, "#include <%s>\n", fs::path(topLevelFile.filename()).replace_extension(".h").string()); + fprintbf(cpp, "#include <%s>\n", fs::path {topLevelFile.filename()}.replace_extension(".h").string()); for (const auto & m : u->modules()) { IceMetaData md {m->getMetaData()}; for (const auto & i : md.values("slicer:include:")) { @@ -526,20 +526,21 @@ namespace Slicer { iname ? *iname : "element"); fprintbf(cpp, "using C%d = ModelPartForComplex< %s::value_type >;\n", components, d->scoped()); - auto addHook = [&](std::string_view name, const char * element, const Slice::TypePtr & t) { + auto addHook = [&](std::string_view name, const char * element, const Slice::TypePtr & t, bool cc) { auto lname = std::string {name}; boost::algorithm::to_lower(lname); fprintbf(cpp, "\tconst std::string hstr_C%d_%d { \"%s\" };\n", components, element, name); fprintbf(cpp, "\tconstexpr C%d::Hook< %s, ", components, Slice::typeToString(t)); createNewModelPartPtrFor(t); - fprintbf(cpp, - ", 0 > hook%d_%s {const_cast<%s (%s::value_type::*)>(&%s::value_type::%s), \"%s\", \"%s\", " - "&hstr_C%d_%s};\n", - components, element, Slice::typeToString(t), d->scoped(), d->scoped(), element, name, lname, + fprintbf(cpp, ", 0 > hook%d_%s {", components, element); + if (cc) { + fprintbf(cpp, "const_cast<%s (%s::value_type::*)>", Slice::typeToString(t), d->scoped()); + } + fprintbf(cpp, "(&%s::value_type::%s), \"%s\", \"%s\", &hstr_C%d_%s};\n", d->scoped(), element, name, lname, components, element); }; - addHook(md.value("slicer:key:").value_or("key"), "first", d->keyType()); - addHook(md.value("slicer:value:").value_or("value"), "second", d->valueType()); + addHook(md.value("slicer:key:").value_or("key"), "first", d->keyType(), true); + addHook(md.value("slicer:value:").value_or("value"), "second", d->valueType(), false); fprintbf(cpp, "constexpr const HooksImpl< %s::value_type, 2 > hooks%d {{{\n", d->scoped(), components); fprintbf(cpp, " &hook%d_first,\n", components); diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index 3a4b5bb..581eae2 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -2,7 +2,14 @@ #include #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 diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index 99b03dd..522b1e9 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -2,8 +2,15 @@ #define SLICER_XML_H #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 #include +#pragma GCC diagnostic pop #include #include diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp index 3d05979..16bfab3 100644 --- a/slicer/xml/testSpecifics.cpp +++ b/slicer/xml/testSpecifics.cpp @@ -49,8 +49,8 @@ BOOST_AUTO_TEST_CASE(int_values) BOOST_AUTO_TEST_CASE(factories) { - BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".xml", "/some.xml"))); - BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".xml", "/some.xml"))); - BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/xml", std::cout))); - BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/xml", std::cin))); + BOOST_REQUIRE(Slicer::FileSerializerFactory::createNew(".xml", "/some.xml")); + BOOST_REQUIRE(Slicer::FileDeserializerFactory::createNew(".xml", "/some.xml")); + BOOST_REQUIRE(Slicer::StreamSerializerFactory::createNew("application/xml", std::cout)); + BOOST_REQUIRE(Slicer::StreamDeserializerFactory::createNew("application/xml", std::cin)); } -- cgit v1.2.3