From 74984c2a06514ec5eef835070adc3f9fd8c18012 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 23 Sep 2021 20:06:30 +0100 Subject: Add -Wconversion and -Wsign-conversion --- Jamroot.jam | 2 ++ slicer/db/sqlInsertSerializer.cpp | 18 +++++++++--------- slicer/db/sqlInsertSerializer.h | 12 ++++++------ slicer/db/sqlUpdateSerializer.cpp | 4 ++-- slicer/ice/serializer.cpp | 2 +- slicer/ice/testSpecifics.cpp | 10 +++++----- slicer/test/conversions.cpp | 7 ++++++- slicer/tool/icemetadata.cpp | 2 +- 8 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 8e63adb..b1dc307 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -23,6 +23,8 @@ project debug:-Wunused debug:-Woverloaded-virtual debug:-Wpedantic + debug:-Wconversion + debug:-Wsign-conversion debug:-Wnull-dereference debug:-Wdouble-promotion debug:-Wformat=2 diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index 4061b17..f18df73 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -1,6 +1,6 @@ +#include "sqlInsertSerializer.h" #include "sqlBinder.h" #include "sqlCommon.h" -#include "sqlInsertSerializer.h" #include #include #include @@ -56,7 +56,7 @@ namespace Slicer { void SqlInsertSerializer::bindObjectAndExecute(const Slicer::ModelPartPtr & cmp, DB::ModifyCommand * ins) const { - int paramNo = 0; + unsigned int paramNo = 0; cmp->OnEachChild([this, ¶mNo, ins](auto &&, auto && PH2, auto && PH3) { bindObjectAndExecuteField(paramNo, ins, PH2, PH3); }); @@ -109,8 +109,8 @@ namespace Slicer { } void - SqlInsertSerializer::bindObjectAndExecuteField( - int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const + SqlInsertSerializer::bindObjectAndExecuteField(unsigned int & paramNo, DB::ModifyCommand * ins, + const Slicer::ModelPartPtr & cmp, const HookCommon * h) const { if (isBind(h)) { if (!cmp->GetValue(SqlBinder(*ins, paramNo))) { @@ -121,8 +121,8 @@ namespace Slicer { } void - SqlAutoIdInsertSerializer::bindObjectAndExecuteField( - int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const + SqlAutoIdInsertSerializer::bindObjectAndExecuteField(unsigned int & paramNo, DB::ModifyCommand * ins, + const Slicer::ModelPartPtr & cmp, const HookCommon * h) const { if (isNotAuto(h)) { SqlInsertSerializer::bindObjectAndExecuteField(paramNo, ins, cmp, h); @@ -135,7 +135,7 @@ namespace Slicer { using namespace AdHoc::literals; std::stringstream insert; "INSERT INTO %?("_fmt(insert, tableName); - int fieldNo = 0; + unsigned int fieldNo = 0; mp->OnEachChild([this, &fieldNo, &insert](auto && PH1, auto &&, auto && PH3) { createInsertField(fieldNo, insert, PH1, PH3); }); @@ -149,7 +149,7 @@ namespace Slicer { void SqlInsertSerializer::createInsertField( - int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const + unsigned int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const { if (isBind(h)) { if (fieldNo++) { @@ -161,7 +161,7 @@ namespace Slicer { void SqlAutoIdInsertSerializer::createInsertField( - int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const + unsigned int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const { if (isNotAuto(h)) { if (fieldNo++) { diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index b964b5e..8a72b68 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -18,10 +18,10 @@ namespace Slicer { void SerializeSequence(const Slicer::ModelPartPtr &) const; DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const; virtual void createInsertField( - int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; + unsigned int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; virtual void bindObjectAndExecuteField( - int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; + unsigned int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; DB::Connection * const connection; const std::string tableName; @@ -32,10 +32,10 @@ namespace Slicer { 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 override; - virtual void bindObjectAndExecuteField( - int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const override; + virtual void createInsertField(unsigned int & fieldNo, std::ostream & insert, const std::string & name, + const HookCommon * h) const override; + virtual void bindObjectAndExecuteField(unsigned int & paramNo, DB::ModifyCommand *, + const Slicer::ModelPartPtr &, const HookCommon *) const override; }; class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer { diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 29d9da7..a2de6a7 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -1,6 +1,6 @@ +#include "sqlUpdateSerializer.h" #include "sqlBinder.h" #include "sqlCommon.h" -#include "sqlUpdateSerializer.h" #include #include #include @@ -54,7 +54,7 @@ namespace Slicer { void SqlUpdateSerializer::bindObjectAndExecute(const Slicer::ModelPartPtr & cmp, DB::ModifyCommand * upd) { - int paramNo = 0; + unsigned int paramNo = 0; cmp->OnEachChild([&upd, ¶mNo](const std::string &, const ModelPartPtr & cmp, const HookCommon * h) { if (isValue(h)) { if (!cmp->GetValue(SqlBinder(*upd, paramNo))) { diff --git a/slicer/ice/serializer.cpp b/slicer/ice/serializer.cpp index 8f83352..523b977 100644 --- a/slicer/ice/serializer.cpp +++ b/slicer/ice/serializer.cpp @@ -30,7 +30,7 @@ namespace Slicer { IceStreamSerializer::Serialize(ModelPartForRootPtr mp) { IceBlobSerializer::Serialize(mp); - strm.write(reinterpret_cast(blob.data()), blob.size()); + strm.write(reinterpret_cast(blob.data()), static_cast(blob.size())); } IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : refblob(b) { } diff --git a/slicer/ice/testSpecifics.cpp b/slicer/ice/testSpecifics.cpp index d24fd00..50742e4 100644 --- a/slicer/ice/testSpecifics.cpp +++ b/slicer/ice/testSpecifics.cpp @@ -43,8 +43,8 @@ BOOST_AUTO_TEST_CASE(builtins) testCompare(3434090); testCompare(-4000033); testCompare(343409898900); - testCompare(-3.14); - testCompare(3.14); + testCompare(-3.14F); + testCompare(3.14F); testCompare(-3.14159); testCompare(3.14159); } @@ -78,8 +78,8 @@ BOOST_AUTO_TEST_CASE(optionalBuiltins) testCompareOptional(3434090); testCompareOptional(-4000033); testCompareOptional(343409898900); - testCompareOptional(-3.14); - testCompareOptional(3.14); + testCompareOptional(-3.14F); + testCompareOptional(3.14F); testCompareOptional(-3.14159); testCompareOptional(3.14159); } @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(classes) x->mshort = 31434; x->mint = 324324234; x->mlong = 343242342343243; - x->mfloat = 3434.32432; + x->mfloat = 3434.32432F; x->mdouble = 3423423423.42342342343; x->mstring = "sdfsf432423"; testCompare(x, [](const auto & a, const auto & b) { diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index 502975e..ff4371a 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -2,13 +2,18 @@ #include #define SHORT(x) boost::numeric_cast<::Ice::Short, int64_t>(x) +inline auto +USHORT(std::integral auto x) +{ + return boost::numeric_cast(x); +} namespace Slicer { DLL_PUBLIC boost::posix_time::ptime dateTimeToPTime(const ::TestModule::DateTime & dt) { - return boost::posix_time::ptime(boost::gregorian::date(dt.year, dt.month, dt.day), + return boost::posix_time::ptime(boost::gregorian::date(USHORT(dt.year), USHORT(dt.month), USHORT(dt.day)), boost::posix_time::time_duration(dt.hour, dt.minute, dt.second)); } diff --git a/slicer/tool/icemetadata.cpp b/slicer/tool/icemetadata.cpp index 0d8d7bc..b575707 100644 --- a/slicer/tool/icemetadata.cpp +++ b/slicer/tool/icemetadata.cpp @@ -38,7 +38,7 @@ namespace Slicer { size_t IceMetaData::countSlicerMetaData() const { - return std::count_if(_begin, _end, isSlicerMetaData); + return static_cast(std::count_if(_begin, _end, isSlicerMetaData)); } bool -- cgit v1.2.3