From 593f223401e17a8eab7b6ace7d2cbc382fa476f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 30 Dec 2021 14:44:53 -0500
Subject: [PATCH] misc: clean warnings

Change-Id: Id0a23dc290e699bbf33cf87857ea92551df9da04
---
 CMakeLists.txt                  |  24 +------
 src/authority/storagehelper.cpp | 122 ++++++++++++++++----------------
 src/authority/storagehelper.h   |  52 --------------
 src/conversationmodel.cpp       |   2 +
 src/database.cpp                |  54 +++++++-------
 src/database.h                  |  12 ++--
 src/dbus/instancemanager.cpp    |   1 +
 src/messagelistmodel.cpp        |   4 +-
 src/newvideo.cpp                |   2 +
 src/qtwrapper/pluginmanager.cpp |   1 -
 10 files changed, 101 insertions(+), 173 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 50ec1a17..775097eb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -122,6 +122,7 @@ if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
 # Enable some useful warnings
     ADD_DEFINITIONS(
        -Wall
+       -pedantic
        -Wextra
        -Wmissing-declarations
        -Wmissing-noreturn
@@ -130,27 +131,13 @@ if (NOT (CMAKE_CXX_COMPILER_ID MATCHES "MSVC"))
        -Wwrite-strings
        -Wformat-nonliteral
        -Wformat-security
-       -Wswitch-enum
-       -Winit-self
        -Wmissing-include-dirs
        -Wundef
        -Wmissing-format-attribute
        -Wno-reorder
        -Wunused
-       -Wuninitialized
        -Woverloaded-virtual
-       -Wunused-value
-       -pedantic
-       -Wnonnull
-       -Wsequence-point
-       #-Wsystem-headers
-       -Wsizeof-pointer-memaccess
-       #-Wuseless-cast
        -Wvarargs
-
-       #See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55578
-       -Wno-unused-function
-       -Wno-attributes
     )
 endif()
 
@@ -163,25 +150,17 @@ endif()
 IF (CMAKE_COMPILER_IS_GNUCC)
    IF (GCC_VERSION VERSION_GREATER 4.9 OR GCC_VERSION VERSION_EQUAL 4.9)
       ADD_DEFINITIONS(
-         -Wunused-but-set-parameter
          -Wconditionally-supported
-         #-Wsuggest-attribute=const
          -Wno-cpp
          -Wdouble-promotion
          -Wdate-time
-         -Wdelete-incomplete
          -Wfloat-conversion
       )
    ENDIF()
 
    if (GCC_VERSION VERSION_GREATER 5.1 OR GCC_VERSION VERSION_EQUAL 5.1)
       ADD_DEFINITIONS(
-         #-Wsuggest-override
-         #-Wsuggest-final-types
-         #-Wsuggest-final-methods
-         -Wbool-compare
          -Wformat-signedness
-         -Wlogical-not-parentheses
          -Wnormalized
          -Wshift-count-negative
          -Wshift-count-overflow
@@ -196,7 +175,6 @@ IF (CMAKE_COMPILER_IS_GNUCC)
          -Wshift-negative-value
          -Wshift-overflow
          -Wduplicated-cond
-         -Wmisleading-indentation
       )
    ENDIF()
 ENDIF()
diff --git a/src/authority/storagehelper.cpp b/src/authority/storagehelper.cpp
index 218ddd87..81c91903 100644
--- a/src/authority/storagehelper.cpp
+++ b/src/authority/storagehelper.cpp
@@ -61,6 +61,66 @@ getPath()
     return dataDir.absolutePath() + "/jami/";
 }
 
+static QString
+profileVcardPath(const QString& accountId, const QString& uri)
+{
+    auto accountLocalPath = getPath() + accountId + QDir::separator();
+    if (uri.isEmpty())
+        return accountLocalPath + "profile.vcf";
+
+    auto fileName = QString(uri.toUtf8().toBase64());
+    return accountLocalPath + "profiles" + QDir::separator() + fileName + ".vcf";
+}
+
+static QString
+stringFromJSON(const QJsonObject& json)
+{
+    QJsonDocument doc(json);
+    return QString::fromLocal8Bit(doc.toJson(QJsonDocument::Compact));
+}
+
+static QJsonObject
+JSONFromString(const QString& str)
+{
+    QJsonObject json;
+    QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8());
+
+    if (!doc.isNull()) {
+        if (doc.isObject()) {
+            json = doc.object();
+        } else {
+            qDebug() << "Document is not a JSON object: " << str;
+        }
+    } else {
+        qDebug() << "Invalid JSON: " << str;
+    }
+    return json;
+}
+
+static QString
+JSONStringFromInitList(const std::initializer_list<QPair<QString, QJsonValue>> args)
+{
+    QJsonObject jsonObject(args);
+    return stringFromJSON(jsonObject);
+}
+
+static QString
+readJSONValue(const QJsonObject& json, const QString& key)
+{
+    if (!json.isEmpty() && json.contains(key) && json[key].isString()) {
+        if (json[key].isString()) {
+            return json[key].toString();
+        }
+    }
+    return {};
+}
+
+static void
+writeJSONValue(QJsonObject& json, const QString& key, const QString& value)
+{
+    json[key] = value;
+}
+
 QString
 prepareUri(const QString& uri, api::profile::Type type)
 {
@@ -752,68 +812,6 @@ getLastTimestamp(Database& db)
     return result;
 }
 
-namespace {
-QString
-profileVcardPath(const QString& accountId, const QString& uri)
-{
-    auto accountLocalPath = getPath() + accountId + QDir::separator();
-    if (uri.isEmpty())
-        return accountLocalPath + "profile.vcf";
-
-    auto fileName = QString(uri.toUtf8().toBase64());
-    return accountLocalPath + "profiles" + QDir::separator() + fileName + ".vcf";
-}
-
-QString
-stringFromJSON(const QJsonObject& json)
-{
-    QJsonDocument doc(json);
-    return QString::fromLocal8Bit(doc.toJson(QJsonDocument::Compact));
-}
-
-QJsonObject
-JSONFromString(const QString& str)
-{
-    QJsonObject json;
-    QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8());
-
-    if (!doc.isNull()) {
-        if (doc.isObject()) {
-            json = doc.object();
-        } else {
-            qDebug() << "Document is not a JSON object: " << str;
-        }
-    } else {
-        qDebug() << "Invalid JSON: " << str;
-    }
-    return json;
-}
-
-QString
-JSONStringFromInitList(const std::initializer_list<QPair<QString, QJsonValue>> args)
-{
-    QJsonObject jsonObject(args);
-    return stringFromJSON(jsonObject);
-}
-
-QString
-readJSONValue(const QJsonObject& json, const QString& key)
-{
-    if (!json.isEmpty() && json.contains(key) && json[key].isString()) {
-        if (json[key].isString()) {
-            return json[key].toString();
-        }
-    }
-    return {};
-}
-
-void
-writeJSONValue(QJsonObject& json, const QString& key, const QString& value)
-{
-    json[key] = value;
-}
-} // namespace
-
 //================================================================================
 // This section provides migration helpers from ring.db
 // to per-account databases yielding a file structure like:
diff --git a/src/authority/storagehelper.h b/src/authority/storagehelper.h
index d62c31ec..656cdb99 100644
--- a/src/authority/storagehelper.h
+++ b/src/authority/storagehelper.h
@@ -356,58 +356,6 @@ QString conversationIdFromInteractionId(Database& db, const QString& interaction
  */
 uint64_t getLastTimestamp(Database& db);
 
-/**
- * JSON parsing functions intended for use with the
- * extra_data columns(conversations and interactions)
- */
-namespace {
-/**
- * Transforms a URI so it can be used as a filename across platforms
- * and constructs the vCard filepath
- * @param uri
- * @return the account's vCard path if uri is left empty,
- * otherwise uri's vCard filepath
- */
-QString profileVcardPath(const QString& accountId, const QString& uri = {});
-
-/**
- * Build a string from a QJsonObject
- * @param  json
- * @return a JSON as a QString
- */
-QString stringFromJSON(const QJsonObject& json);
-
-/**
- * Build a QJsonObject from a QString
- * @param  str
- * @return a JSON object
- */
-QJsonObject JSONFromString(const QString& str);
-
-/**
- * Build a string from an initializer list of key/value pairs
- * @param  args
- * @return a JSON as a QString
- */
-QString JSONStringFromInitList(const std::initializer_list<QPair<QString, QJsonValue>> args);
-
-/**
- * Get the value at a key from a JSON object
- * @param  json
- * @param  key
- * @return the value as a QString
- */
-QString readJSONValue(const QJsonObject& json, const QString& key);
-
-/**
- * Store a value at a key in a JSON object
- * @param  json
- * @param  key
- * @param  value
- */
-void writeJSONValue(QJsonObject& json, const QString& key, const QString& value);
-} // namespace
-
 /**
  * Retrieve a list of account database via a migration
  * procedure from the legacy "ring.db", if it exists
diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp
index f57c50a1..b74527e1 100644
--- a/src/conversationmodel.cpp
+++ b/src/conversationmodel.cpp
@@ -632,6 +632,8 @@ ConversationModel::getFilteredConversations(const profile::Type& profileType,
     case lrc::api::profile::Type::SIP:
         filterType = lrc::api::FilterType::SIP;
         break;
+    default:
+        break;
     }
 
     return getFilteredConversations(filterType, forceUpdate, includeBanned);
diff --git a/src/database.cpp b/src/database.cpp
index 9ea4055b..0ddefb4a 100644
--- a/src/database.cpp
+++ b/src/database.cpp
@@ -156,14 +156,14 @@ Database::createTables()
     // add conversations table
     if (!db_.tables().contains("conversations", Qt::CaseInsensitive)) {
         if (!query.exec(tableConversations) || !query.exec(indexConversations)) {
-            throw QueryError(query);
+            throw QueryError(std::move(query));
         }
     }
 
     // add interactions table
     if (!db_.tables().contains("interactions", Qt::CaseInsensitive)) {
         if (!query.exec(tableInteractions) || !query.exec(indexInteractions)) {
-            throw QueryError(query);
+            throw QueryError(std::move(query));
         }
     }
 
@@ -202,7 +202,7 @@ Database::storeVersion(const QString& version)
     auto storeVersionQuery = "PRAGMA user_version = " + version;
 
     if (not query.exec(storeVersionQuery))
-        throw QueryError(query);
+        throw QueryError(std::move(query));
 
     qDebug() << "database " << databaseFullPath_ << " version set to:" << version;
 }
@@ -213,7 +213,7 @@ Database::getVersion()
     QSqlQuery query(db_);
     auto getVersionQuery = "pragma user_version";
     if (not query.exec(getVersionQuery))
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     query.first();
     return query.value(0).toString();
 }
@@ -245,10 +245,10 @@ Database::insertInto(
         query.bindValue(entry.first, entry.second);
 
     if (not query.exec())
-        throw QueryInsertError(query, table, bindCol, bindsSet);
+        throw QueryInsertError(std::move(query), table, bindCol, bindsSet);
 
     if (not query.exec("SELECT last_insert_rowid()"))
-        throw QueryInsertError(query, table, bindCol, bindsSet);
+        throw QueryInsertError(std::move(query), table, bindCol, bindsSet);
 
     if (!query.next())
         return QString::number(-1);
@@ -276,7 +276,7 @@ Database::update(const QString& table,              // "tests"
         query.bindValue(entry.first, entry.second);
 
     if (not query.exec())
-        throw QueryUpdateError(query, table, set, bindsSet, where, bindsWhere);
+        throw QueryUpdateError(std::move(query), table, set, bindsSet, where, bindsWhere);
 }
 
 Database::Result
@@ -296,7 +296,7 @@ Database::select(const QString& select,             // "id", "body", ...
         query.bindValue(entry.first, entry.second);
 
     if (not query.exec())
-        throw QuerySelectError(query, select, table, where, bindsWhere);
+        throw QuerySelectError(std::move(query), select, table, where, bindsWhere);
 
     QSqlRecord rec = query.record();
     const auto col_num = rec.count();
@@ -326,7 +326,7 @@ Database::count(const QString& count,              // "id", "body", ...
         query.bindValue(entry.first, entry.second);
 
     if (not query.exec())
-        throw QueryError(query);
+        throw QueryError(std::move(query));
 
     query.next();
     return query.value(0).toInt();
@@ -346,19 +346,19 @@ Database::deleteFrom(const QString& table,              // "tests"
         query.bindValue(entry.first, entry.second);
 
     if (not query.exec())
-        throw QueryDeleteError(query, table, where, bindsWhere);
+        throw QueryDeleteError(std::move(query), table, where, bindsWhere);
 }
 
-Database::QueryError::QueryError(const QSqlQuery& query)
+Database::QueryError::QueryError(QSqlQuery&& query)
     : std::runtime_error(query.lastError().text().toStdString())
-    , query(query)
+    , query(std::move(query))
 {}
 
-Database::QueryInsertError::QueryInsertError(const QSqlQuery& query,
+Database::QueryInsertError::QueryInsertError(QSqlQuery&& query,
                                              const QString& table,
                                              const MapStringString& bindCol,
                                              const MapStringString& bindsSet)
-    : QueryError(query)
+    : QueryError(std::move(query))
     , table(table)
     , bindCol(bindCol)
     , bindsSet(bindsSet)
@@ -377,13 +377,13 @@ Database::QueryInsertError::details()
     return qts.readAll();
 }
 
-Database::QueryUpdateError::QueryUpdateError(const QSqlQuery& query,
+Database::QueryUpdateError::QueryUpdateError(QSqlQuery&& query,
                                              const QString& table,
                                              const QString& set,
                                              const MapStringString& bindsSet,
                                              const QString& where,
                                              const MapStringString& bindsWhere)
-    : QueryError(query)
+    : QueryError(std::move(query))
     , table(table)
     , set(set)
     , bindsSet(bindsSet)
@@ -408,12 +408,12 @@ Database::QueryUpdateError::details()
     return qts.readAll();
 }
 
-Database::QuerySelectError::QuerySelectError(const QSqlQuery& query,
+Database::QuerySelectError::QuerySelectError(QSqlQuery&& query,
                                              const QString& select,
                                              const QString& table,
                                              const QString& where,
                                              const MapStringString& bindsWhere)
-    : QueryError(query)
+    : QueryError(std::move(query))
     , select(select)
     , table(table)
     , where(where)
@@ -434,11 +434,11 @@ Database::QuerySelectError::details()
     return qts.readAll();
 }
 
-Database::QueryDeleteError::QueryDeleteError(const QSqlQuery& query,
+Database::QueryDeleteError::QueryDeleteError(QSqlQuery&& query,
                                              const QString& table,
                                              const QString& where,
                                              const MapStringString& bindsWhere)
-    : QueryError(query)
+    : QueryError(std::move(query))
     , table(table)
     , where(where)
     , bindsWhere(bindsWhere)
@@ -457,8 +457,8 @@ Database::QueryDeleteError::details()
     return qts.readAll();
 }
 
-Database::QueryTruncateError::QueryTruncateError(const QSqlQuery& query, const QString& table)
-    : QueryError(query)
+Database::QueryTruncateError::QueryTruncateError(QSqlQuery&& query, const QString& table)
+    : QueryError(std::move(query))
     , table(table)
 {}
 
@@ -554,25 +554,25 @@ LegacyDatabase::createTables()
     // add profiles table
     if (not db_.tables().contains("profiles", Qt::CaseInsensitive)
         and not query.exec(tableProfiles)) {
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     }
 
     // add conversations table
     if (not db_.tables().contains("conversations", Qt::CaseInsensitive)
         and not query.exec(tableConversations)) {
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     }
 
     // add interactions table
     if (not db_.tables().contains("interactions", Qt::CaseInsensitive)
         and not query.exec(tableInteractions)) {
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     }
 
     // add profiles accounts table
     if (not db_.tables().contains("profiles_accounts", Qt::CaseInsensitive)
         and not query.exec(tableProfileAccounts)) {
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     }
 
     storeVersion(version_);
@@ -889,7 +889,7 @@ LegacyDatabase::migrateSchemaFromVersion1()
     // add profiles accounts table
     if (not db_.tables().contains("profiles_accounts", Qt::CaseInsensitive)
         and not query.exec(tableProfileAccounts)) {
-        throw QueryError(query);
+        throw QueryError(std::move(query));
     }
     linkRingProfilesWithAccounts(false);
 }
diff --git a/src/database.h b/src/database.h
index f8227e21..2eafe3af 100644
--- a/src/database.h
+++ b/src/database.h
@@ -84,7 +84,7 @@ public:
     class QueryError : public std::runtime_error
     {
     public:
-        explicit QueryError(const QSqlQuery& query);
+        explicit QueryError(QSqlQuery&& query);
         virtual QString details() { return {}; }
 
         const QSqlQuery query;
@@ -97,7 +97,7 @@ public:
     class QueryInsertError final : public QueryError
     {
     public:
-        explicit QueryInsertError(const QSqlQuery& query,
+        explicit QueryInsertError(QSqlQuery&& query,
                                   const QString& table,
                                   const MapStringString& bindCol,
                                   const MapStringString& bindsSet);
@@ -115,7 +115,7 @@ public:
     class QueryUpdateError final : public QueryError
     {
     public:
-        explicit QueryUpdateError(const QSqlQuery& query,
+        explicit QueryUpdateError(QSqlQuery&& query,
                                   const QString& table,
                                   const QString& set,
                                   const MapStringString& bindsSet,
@@ -137,7 +137,7 @@ public:
     class QuerySelectError final : public QueryError
     {
     public:
-        explicit QuerySelectError(const QSqlQuery& query,
+        explicit QuerySelectError(QSqlQuery&& query,
                                   const QString& select,
                                   const QString& table,
                                   const QString& where,
@@ -157,7 +157,7 @@ public:
     class QueryDeleteError final : public QueryError
     {
     public:
-        explicit QueryDeleteError(const QSqlQuery& query,
+        explicit QueryDeleteError(QSqlQuery&& query,
                                   const QString& table,
                                   const QString& where,
                                   const MapStringString& bindsWhere);
@@ -175,7 +175,7 @@ public:
     class QueryTruncateError final : public QueryError
     {
     public:
-        explicit QueryTruncateError(const QSqlQuery& query, const QString& table);
+        explicit QueryTruncateError(QSqlQuery&& query, const QString& table);
         QString details() override;
 
         const QString table;
diff --git a/src/dbus/instancemanager.cpp b/src/dbus/instancemanager.cpp
index 7c2e16ab..493f99e3 100644
--- a/src/dbus/instancemanager.cpp
+++ b/src/dbus/instancemanager.cpp
@@ -36,6 +36,7 @@ InstanceManager::instance(bool muteDring)
 #else
     if (!dbus_metaTypeInit)
         registerCommTypes();
+    Q_UNUSED(muteDring)
 
     static auto interface = new InstanceManagerInterface("cx.ring.Ring",
                                                          "/cx/ring/Ring/Instance",
diff --git a/src/messagelistmodel.cpp b/src/messagelistmodel.cpp
index 165e1476..ff17a3e7 100644
--- a/src/messagelistmodel.cpp
+++ b/src/messagelistmodel.cpp
@@ -312,7 +312,7 @@ MessageListModel::contains(const QString& msgId)
 }
 
 int
-MessageListModel::rowCount(const QModelIndex& parent) const
+MessageListModel::rowCount(const QModelIndex&) const
 {
     return interactions_.size();
 }
@@ -329,7 +329,7 @@ MessageListModel::roleNames() const
 }
 
 QVariant
-MessageListModel::dataForItem(item_t item, int indexRow, int role) const
+MessageListModel::dataForItem(item_t item, int, int role) const
 {
     switch (role) {
     case Role::Id:
diff --git a/src/newvideo.cpp b/src/newvideo.cpp
index 9c9e115c..80bbf1db 100644
--- a/src/newvideo.cpp
+++ b/src/newvideo.cpp
@@ -105,6 +105,7 @@ Renderer::update(const QString& res, const QString& shmPath)
     pimpl_->renderer->setSize(size);
 
 #ifdef ENABLE_LIBWRAP
+    Q_UNUSED(shmPath)
     if (pimpl_->usingAVFrame_) {
         VideoManager::instance().registerAVSinkTarget(pimpl_->id_, pimpl_->renderer->avTarget());
     } else {
@@ -191,6 +192,7 @@ RendererPimpl::RendererPimpl(Renderer& linked,
 {
     QSize size = stringToQSize(videoSettings.size);
 #ifdef ENABLE_LIBWRAP
+    Q_UNUSED(shmPath)
     renderer = std::make_unique<Video::DirectRenderer>(id, size, usingAVFrame_);
 #else // ENABLE_LIBWRAP
     renderer = std::make_unique<Video::ShmRenderer>(id, shmPath, size);
diff --git a/src/qtwrapper/pluginmanager.cpp b/src/qtwrapper/pluginmanager.cpp
index ba9f8f94..9201ffe7 100644
--- a/src/qtwrapper/pluginmanager.cpp
+++ b/src/qtwrapper/pluginmanager.cpp
@@ -15,7 +15,6 @@
  *   You should have received a copy of the Lesser GNU General Public License *
  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
  *****************************************************************************/
-#pragma once
 
 #include "pluginmanager_wrap.h"
 
-- 
GitLab