summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-09-23 19:12:28 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-09-23 19:22:59 +0100
commit781269fe3e20ebbfa2cf6c2b1aaae3bd7dc3d8e4 (patch)
treec5bbdded6262da424fceb792aa5e3c368497f756
parentAdd missing includes (diff)
downloadslicer-781269fe3e20ebbfa2cf6c2b1aaae3bd7dc3d8e4.tar.bz2
slicer-781269fe3e20ebbfa2cf6c2b1aaae3bd7dc3d8e4.tar.xz
slicer-781269fe3e20ebbfa2cf6c2b1aaae3bd7dc3d8e4.zip
Remove unnecessary casts
-rw-r--r--Jamroot.jam1
-rw-r--r--slicer/json/testSpecifics.cpp20
-rw-r--r--slicer/tool/parser.cpp17
-rw-r--r--slicer/xml/serializer.cpp7
-rw-r--r--slicer/xml/serializer.h7
-rw-r--r--slicer/xml/testSpecifics.cpp8
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
<variant>debug:<warnings-as-errors>on
<variant>debug:<cflags>-Wnon-virtual-dtor
<variant>debug:<cflags>-Woverloaded-virtual
+ <toolset>gcc,<variant>debug:<cflags>-Wuseless-cast
<variant>coverage:<coverage>on
<toolset>tidy:<checkxx>boost-*
<toolset>tidy:<checkxx>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 <boost/lexical_cast.hpp>
#include <compileTimeFormatter.h>
#include <functional>
+#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 <glibmm/ustring.h>
+#pragma GCC diagnostic pop
#include <libxml++/document.h>
#include <libxml++/parsers/domparser.h>
#include <slicer/metadata.h>
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 <lazyPointer.h>
+#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 <libxml++/document.h>
#include <libxml++/nodes/element.h>
+#pragma GCC diagnostic pop
#include <slicer/serializer.h>
#include <visibility.h>
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));
}