From 5afe78d015d206bc291d14468608b11af158f8cd Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 30 Mar 2019 17:15:21 -0500 Subject: [PATCH] [nostalgia] Enable and fix several warnings --- CMakeLists.txt | 15 +++++++++++++++ src/nostalgia/studio/lib/json.hpp | 2 ++ src/nostalgia/studio/lib/json_test.cpp | 18 +++++++++--------- src/nostalgia/studio/lib/plugin.hpp | 4 ++++ src/nostalgia/studio/lib/project.cpp | 2 +- src/nostalgia/studio/lib/project.hpp | 4 ++-- src/nostalgia/studio/main.cpp | 2 +- src/nostalgia/studio/mainwindow.cpp | 2 +- src/nostalgia/tools/CMakeLists.txt | 6 ++---- src/nostalgia/tools/lib/tilesetimport.cpp | 17 +++++++++-------- src/nostalgia/tools/pack.cpp | 14 +++++++------- 11 files changed, 53 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a50b9640..b16923d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,20 @@ endif() if(NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable") if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA") include(GBA) @@ -39,6 +52,8 @@ if(NOT MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb-interwork") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=arm7tdmi") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=arm7tdmi") set(OX_USE_STDLIB OFF) endif() diff --git a/src/nostalgia/studio/lib/json.hpp b/src/nostalgia/studio/lib/json.hpp index 947586f9..6f6c82c2 100644 --- a/src/nostalgia/studio/lib/json.hpp +++ b/src/nostalgia/studio/lib/json.hpp @@ -17,6 +17,8 @@ namespace studio { class JsonOperator { public: + virtual ~JsonOperator() = default; + virtual int op(QString fieldName, int *dest) = 0; virtual int op(QString fieldName, bool *dest) = 0; diff --git a/src/nostalgia/studio/lib/json_test.cpp b/src/nostalgia/studio/lib/json_test.cpp index e0b46fc0..49017e31 100644 --- a/src/nostalgia/studio/lib/json_test.cpp +++ b/src/nostalgia/studio/lib/json_test.cpp @@ -55,15 +55,15 @@ int main(int argc, char **args) { int err = 0; QString json; TestStruct ts = { - .Bool = true, - .Int = 42, - .Double = 42.42, - .String = "Test String", - .Struct = { - .Bool = true, - .Int = 42, - .Double = 42.42, - .String = "Test String" + true, + 42, + 42.42, + "Test String", + { + true, + 42, + 42.42, + "Test String" } }; TestStruct tsOut; diff --git a/src/nostalgia/studio/lib/plugin.hpp b/src/nostalgia/studio/lib/plugin.hpp index 9d8d9f22..717933bc 100644 --- a/src/nostalgia/studio/lib/plugin.hpp +++ b/src/nostalgia/studio/lib/plugin.hpp @@ -28,12 +28,16 @@ struct Context { }; struct EditorMaker { + virtual ~EditorMaker() = default; + virtual QWidget *make(QString path, const Context *ctx) = 0; }; class Plugin { public: + virtual ~Plugin() = default; + virtual QVector newWizards(const Context *ctx); virtual QVector importWizards(const Context *ctx); diff --git a/src/nostalgia/studio/lib/project.cpp b/src/nostalgia/studio/lib/project.cpp index 686819b7..85099434 100644 --- a/src/nostalgia/studio/lib/project.cpp +++ b/src/nostalgia/studio/lib/project.cpp @@ -35,7 +35,7 @@ int Project::openRomFs() { auto buff = std::make_unique(buffSize); if (file.exists()) { file.open(QIODevice::ReadOnly); - if (file.read((char*) buff.get(), buffSize) > 0) { + if (file.read(reinterpret_cast(buff.get()), buffSize) > 0) { m_fsBuff = std::move(buff); if (m_fs.valid()) { return 0; diff --git a/src/nostalgia/studio/lib/project.hpp b/src/nostalgia/studio/lib/project.hpp index 1a526af0..e489bb16 100644 --- a/src/nostalgia/studio/lib/project.hpp +++ b/src/nostalgia/studio/lib/project.hpp @@ -66,13 +66,13 @@ int Project::writeObj(QString path, T *obj) const { // write MetalClaw size_t mcSize = 0; - err |= ox::writeMC((uint8_t*) buff.data(), buffLen, obj, &mcSize); + err |= ox::writeMC(reinterpret_cast(buff.data()), buffLen, obj, &mcSize); if (err) { return err; } // write to FS - err |= write(path, (uint8_t*) buff.data(), mcSize); + err |= write(path, reinterpret_cast(buff.data()), mcSize); if (err) { return err; } diff --git a/src/nostalgia/studio/main.cpp b/src/nostalgia/studio/main.cpp index 3339352b..2b0744b2 100644 --- a/src/nostalgia/studio/main.cpp +++ b/src/nostalgia/studio/main.cpp @@ -17,7 +17,7 @@ using namespace nostalgia::studio; using namespace ox; int run(int argc, char **args) { - ClArgs clargs(argc, (const char**) args); + ClArgs clargs(argc, const_cast(args)); QString argProfilePath = clargs.getString("profile").c_str(); NostalgiaStudioProfile config; diff --git a/src/nostalgia/studio/mainwindow.cpp b/src/nostalgia/studio/mainwindow.cpp index 034f8271..015cea8b 100644 --- a/src/nostalgia/studio/mainwindow.cpp +++ b/src/nostalgia/studio/mainwindow.cpp @@ -151,7 +151,7 @@ void MainWindow::setupProjectExplorer() { dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); dock->setObjectName("Project Explorer"); addDockWidget(Qt::LeftDockWidgetArea, dock); - resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal); + resizeDocks({dock}, {static_cast(width() * 0.25)}, Qt::Horizontal); // setup tree view m_projectExplorer = new QTreeView(dock); diff --git a/src/nostalgia/tools/CMakeLists.txt b/src/nostalgia/tools/CMakeLists.txt index 101c9217..8dc63218 100644 --- a/src/nostalgia/tools/CMakeLists.txt +++ b/src/nostalgia/tools/CMakeLists.txt @@ -1,7 +1,3 @@ -cmake_minimum_required(VERSION 2.8.11) - -project(nost-pack) - set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) @@ -25,4 +21,6 @@ install( bin ) + add_subdirectory(lib) +add_subdirectory(pack) diff --git a/src/nostalgia/tools/lib/tilesetimport.cpp b/src/nostalgia/tools/lib/tilesetimport.cpp index d9a49120..dc143d35 100644 --- a/src/nostalgia/tools/lib/tilesetimport.cpp +++ b/src/nostalgia/tools/lib/tilesetimport.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -22,10 +23,10 @@ using namespace ox; using namespace nostalgia::core; using namespace nostalgia::common; -uint16_t toGbaColor(QColor c) { - auto r = ((uint32_t) c.red()) >> 3; - auto g = ((uint32_t) c.green()) >> 3; - auto b = ((uint32_t) c.blue()) >> 3; +[[nodiscard]] uint16_t toGbaColor(QColor c) { + const auto r = static_cast(c.red()) >> 3; + const auto g = static_cast(c.green()) >> 3; + const auto b = static_cast(c.blue()) >> 3; return (r << 10) | (g << 5) | (b << 0); } @@ -47,9 +48,9 @@ Error importTileSet(FileSystem *fs, QString romPath, QString importPath, int bpp QMap colors; auto tileCount = (src.width() * src.height()) / 64; const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + tileCount * 64; - uint8_t imgDataBuff[imgDataBuffSize]; - memset(&imgDataBuff, 0, imgDataBuffSize); - GbaImageData *id = (GbaImageData*) imgDataBuff; + QVector imgDataBuff(imgDataBuffSize); + memset(imgDataBuff.data(), 0, imgDataBuffSize); + GbaImageData *id = reinterpret_cast(imgDataBuff.data()); id->header.bpp = bpp; id->header.tileCount = tileCount; int colorId = 0; @@ -84,7 +85,7 @@ Error importTileSet(FileSystem *fs, QString romPath, QString importPath, int bpp } if (!err) { - err |= fs->write(romPath.toUtf8().data(), imgDataBuff, imgDataBuffSize); + err |= fs->write(romPath.toUtf8().data(), imgDataBuff.data(), imgDataBuffSize); } } else { err = 4; diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 0c904af3..7d3e76a8 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -39,9 +39,9 @@ uint8_t *loadFileBuff(QString path, ::size_t *sizeOut = nullptr) { } uint16_t toGbaColor(QColor c) { - auto r = ((uint32_t) c.red()) >> 3; - auto g = ((uint32_t) c.green()) >> 3; - auto b = ((uint32_t) c.blue()) >> 3; + auto r = static_cast(c.red()) >> 3; + auto g = static_cast(c.green()) >> 3; + auto b = static_cast(c.blue()) >> 3; return (r << 10) | (g << 5) | (b << 0); } @@ -76,9 +76,9 @@ int run(ClArgs args) { QMap colors; const auto imgDataBuffSize = sizeof(GbaImageData) + 1 + argTiles * 64; - uint8_t imgDataBuff[imgDataBuffSize]; - memset(&imgDataBuff, 0, imgDataBuffSize); - GbaImageData *id = (GbaImageData*) imgDataBuff; + QVector imgDataBuff(imgDataBuffSize); + memset(imgDataBuff.data(), 0, imgDataBuffSize); + auto id = reinterpret_cast(imgDataBuff.data()); id->header.bpp = argBpp; id->header.tileCount = argTiles; int colorId = 0; @@ -130,7 +130,7 @@ int run(ClArgs args) { fsBuffSize = sizeNeeded; } fsBuff = fs.buff(); // update fsBuff pointer in case there is a new buff - err |= fs.write(argInode, imgDataBuff, imgDataBuffSize); + err |= fs.write(argInode, imgDataBuff.data(), imgDataBuffSize); if (!err) { if (argCompact) {