From 9cebcb6d2104d71697c3e416a84db2358c785611 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 22 Jul 2021 22:21:06 +0200
Subject: [PATCH] BUILD: Fix some warnings

---
 CMakeLists.txt                          | 12 +++++--
 src/Lib/Ass/AssFactory.cc               |  2 +-
 src/Lib/Ass/Line.cc                     |  5 +--
 src/Lib/Ass/Style.cc                    |  2 +-
 src/Lib/Audio.cc                        |  8 ++---
 src/UI/AboutWindow.cc                   |  4 +--
 src/UI/AbstractDocumentView.cc          |  4 +--
 src/UI/DocumentViews/AssLinesView.cc    | 45 +++++++++++++------------
 src/UI/DocumentViews/AudioVisualizer.cc |  2 +-
 src/UI/MainWindow.cc                    |  6 ++--
 10 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d29954b4..0b70d209 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,20 +100,26 @@ target_compile_options(Vivy PRIVATE
     -Wmisleading-indentation -Wnull-dereference -Wdouble-promotion
     -Wformat=2
     -Woverloaded-virtual -Wnon-virtual-dtor
+    -Wignored-qualifiers
+
+    -fopenmp
 )
 
+target_link_libraries(Vivy PRIVATE -fopenmp)
+
 # Some compiler specific warnings and options
 if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
     target_compile_options(Vivy PRIVATE
-        -Wno-unused-private-field   # Skip the unused private fields for now
-        -fopenmp                    # We do OpenMP here
+        -Weverything
+        -Wno-c++98-compat
+        -Wno-extra-semi-stmt
+        -Wno-c++98-c++11-c++14-c++17-compat-pedantic
     )
     target_link_libraries(Vivy PRIVATE
         -fopenmp
     )
 elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
     target_compile_options(Vivy PRIVATE -fopenmp)
-    target_link_libraries(Vivy PRIVATE -fopenmp)
 endif()
 
 set_target_properties(Vivy PROPERTIES
diff --git a/src/Lib/Ass/AssFactory.cc b/src/Lib/Ass/AssFactory.cc
index 06bd5db2..a8768767 100644
--- a/src/Lib/Ass/AssFactory.cc
+++ b/src/Lib/Ass/AssFactory.cc
@@ -89,7 +89,7 @@ AssFactory::checkValidity() const noexcept
     const SectionContent::const_iterator end = assInfo.end();
     while (it != end) {
         bool ok = false;
-        if (intTypeFields.contains(it.key()) && (it.value().toInt(&ok), !ok)) {
+        if (intTypeFields.contains(it.key()) && (static_cast<void>(it.value().toInt(&ok)), !ok)) {
             qCritical() << it.key() << "is not an integer:" << it.value();
             return false;
         }
diff --git a/src/Lib/Ass/Line.cc b/src/Lib/Ass/Line.cc
index 7fabdbac..c509af74 100644
--- a/src/Lib/Ass/Line.cc
+++ b/src/Lib/Ass/Line.cc
@@ -24,8 +24,8 @@ Line::Line(AssFactory *const factory, const QString &lineString)
         // NOTE: time is of the form: `h:mm:ss.cc`
     };
 
-    static const QString lineHeader = "Dialogue: ";
-    isComment                       = !lineString.startsWith(lineHeader);
+    const QString lineHeader = QStringLiteral("Dialogue: ");
+    isComment                = !lineString.startsWith(lineHeader);
 
     const QString lineContent = lineString.mid(lineString.indexOf(": ") + 2 /* strlen ": " */);
     QStringList contentList   = lineContent.split(",", Qt::KeepEmptyParts, Qt::CaseInsensitive);
@@ -80,6 +80,7 @@ Line::initSylFromString(const QString &line) noexcept
         }
     } catch (const std::runtime_error &e) {
         qCritical() << "Failed to init syllabes with line:" << line;
+        qCritical() << "Error was:" << e.what();
         qCritical() << "Fallback to all line is one syllabe";
         once = false;
     }
diff --git a/src/Lib/Ass/Style.cc b/src/Lib/Ass/Style.cc
index 80d5eb31..4c2fd133 100644
--- a/src/Lib/Ass/Style.cc
+++ b/src/Lib/Ass/Style.cc
@@ -45,7 +45,7 @@ Style::Style(const QString &styleString)
         PastLastCode
     };
 
-    static const QString lineHeader = "Style: ";
+    const QString lineHeader = QStringLiteral("Style: ");
 
     // Check line header and content items number
 
diff --git a/src/Lib/Audio.cc b/src/Lib/Audio.cc
index e0d7b480..d748fb53 100644
--- a/src/Lib/Audio.cc
+++ b/src/Lib/Audio.cc
@@ -19,12 +19,12 @@ AudioContext::AudioContext(const QString &path)
     AVFormatContext *formatPtr          = format.get();
 
     // Get the format from the audio file
-    if (avformat_open_input(&formatPtr, filename, NULL, NULL) != 0) {
+    if (avformat_open_input(&formatPtr, filename, nullptr, nullptr) != 0) {
         [[maybe_unused]] void *relatedOnFailure = format.release(); // freed by avformat_open_input
         throw std::runtime_error("failed to open file");
     }
 
-    if (avformat_find_stream_info(formatPtr, NULL) < 0) {
+    if (avformat_find_stream_info(formatPtr, nullptr) < 0) {
         throw std::runtime_error("failed to get audio stream info");
     }
 
@@ -106,14 +106,14 @@ AudioContext::getProperties() const noexcept
 // AudioContext::Stream class implementation
 
 // Constructor, need an AVFormat and an AVStream
-AudioContext::Stream::Stream(AVCodec *streamCodec, AVFormatContext *format, AVStream *stream,
+AudioContext::Stream::Stream(AVCodec *streamCodec, AVFormatContext *formatPtr, AVStream *stream,
                              int index)
     : codecId(stream->codecpar->codec_id)
     , codec(streamCodec)
     , codecParams(stream->codecpar)
     , audioStream(stream)
     , streamIndexInAudioContext(index)
-    , dataFormat(format)
+    , dataFormat(formatPtr)
 {
     if (codec == nullptr)
         throw std::runtime_error("failed to find a decoder for stream");
diff --git a/src/UI/AboutWindow.cc b/src/UI/AboutWindow.cc
index 568eb3fc..863f139b 100644
--- a/src/UI/AboutWindow.cc
+++ b/src/UI/AboutWindow.cc
@@ -38,7 +38,7 @@ static const char *libContent =
     "</body>";
 
 // Simple QLabel with some presets
-class SimpleLabel : public QLabel {
+class SimpleLabel final : public QLabel {
 public:
     explicit SimpleLabel(QWidget *parent, const char *text)
         : QLabel(parent)
@@ -52,7 +52,7 @@ public:
 };
 
 // Simple QLabel for licences
-class LicenceLabel : public QTextEdit {
+class LicenceLabel final : public QTextEdit {
 public:
     explicit LicenceLabel(QWidget *parent, const QString &url)
         : QTextEdit(parent)
diff --git a/src/UI/AbstractDocumentView.cc b/src/UI/AbstractDocumentView.cc
index e4b1d386..153948d6 100644
--- a/src/UI/AbstractDocumentView.cc
+++ b/src/UI/AbstractDocumentView.cc
@@ -27,9 +27,9 @@ void
 AbstractDocumentView::deleteAllContent() noexcept
 {
     // Delete all widgets
-    if (layout() != NULL) {
+    if (layout() != nullptr) {
         QLayoutItem *item;
-        while ((item = layout()->takeAt(0)) != NULL) {
+        while ((item = layout()->takeAt(0)) != nullptr) {
             delete item->widget();
             delete item;
         }
diff --git a/src/UI/DocumentViews/AssLinesView.cc b/src/UI/DocumentViews/AssLinesView.cc
index 319e3b06..e390b08b 100644
--- a/src/UI/DocumentViews/AssLinesView.cc
+++ b/src/UI/DocumentViews/AssLinesView.cc
@@ -1,5 +1,6 @@
 #include "AssLinesView.hh"
 #include "../../VivyApplication.hh"
+#include <string_view>
 #include <QPaintEvent>
 #include <QHeaderView>
 
@@ -23,28 +24,28 @@ AssLinesView::AssLinesView(QAbstractItemModel *model, QWidget *parent) noexcept
     setSelectionBehavior(QAbstractItemView::SelectRows);
     setShowGrid(false);
 
-    static const QString style = "* { font-family: \"FiraCode\"; font-size: 8pt; }"
-                                 "QTableView::item:selected {"
-                                 "  border-top:1px solid #1394B4;"
-                                 "  border-bottom:1px solid #1394B4;"
-                                 "  border-right:1px solid #1394B4;"
-                                 "  border-left:1px solid #1394B4;"
-                                 "  background-color: #002B36;"
-                                 "  color: white;"
-                                 "}"
-                                 "QTableView::item {"
-                                 "  border: 1px solid #474747;"
-                                 "  background-color: #232629;"
-                                 "  color: white;"
-                                 "};"
-                                 "QTableView::item:last:selected {"
-                                 "  border-top:1px solid #1394B4;"
-                                 "  border-bottom:1px solid #1394B4;"
-                                 "  border-right:1px solid #1394B4;"
-                                 "  border-left:1px solid #1394B4;"
-                                 "  background-color: #002B36;"
-                                 "  color: white;"
-                                 "}";
+    const QString style = QStringLiteral("* { font-family: \"FiraCode\"; font-size: 8pt; }"
+                                         "QTableView::item:selected {"
+                                         "  border-top:1px solid #1394B4;"
+                                         "  border-bottom:1px solid #1394B4;"
+                                         "  border-right:1px solid #1394B4;"
+                                         "  border-left:1px solid #1394B4;"
+                                         "  background-color: #002B36;"
+                                         "  color: white;"
+                                         "}"
+                                         "QTableView::item {"
+                                         "  border: 1px solid #474747;"
+                                         "  background-color: #232629;"
+                                         "  color: white;"
+                                         "};"
+                                         "QTableView::item:last:selected {"
+                                         "  border-top:1px solid #1394B4;"
+                                         "  border-bottom:1px solid #1394B4;"
+                                         "  border-right:1px solid #1394B4;"
+                                         "  border-left:1px solid #1394B4;"
+                                         "  background-color: #002B36;"
+                                         "  color: white;"
+                                         "}");
     setStyleSheet(style);
     setModel(model);
 }
diff --git a/src/UI/DocumentViews/AudioVisualizer.cc b/src/UI/DocumentViews/AudioVisualizer.cc
index fa8d02c1..60a6279b 100644
--- a/src/UI/DocumentViews/AudioVisualizer.cc
+++ b/src/UI/DocumentViews/AudioVisualizer.cc
@@ -63,7 +63,7 @@ AudioVisualizer::AudioVisualizer(AudioContext::StreamPtr stream, QWidget *parent
             const float re     = chunkData[j * 2 + 1];
             const float mag    = sqrtf(im * im + re * re);
             const size_t index = static_cast<size_t>(j * static_cast<ulong>(width) + x);
-            pixels[index]      = (unsigned char)(mag)*MAXPIXVALUE;
+            pixels[index]      = static_cast<unsigned char>((mag)*MAXPIXVALUE);
         }
     }
 
diff --git a/src/UI/MainWindow.cc b/src/UI/MainWindow.cc
index 08eb9cdd..c4325c55 100644
--- a/src/UI/MainWindow.cc
+++ b/src/UI/MainWindow.cc
@@ -170,7 +170,7 @@ MainWindow::getCurrentDocument() const noexcept
     try {
         return getCurrentDocumentView()->getDocument();
     } catch (const std::runtime_error &e) {
-        qCritical() << "No current view in the main window";
+        qCritical() << "No current view in the main window:" << e.what();
         return nullptr;
     }
 }
@@ -225,7 +225,7 @@ MainWindow::newDocument() noexcept
     try {
         addTab(new VivyDocumentView(document));
     } catch (const std::runtime_error &e) {
-        qCritical() << "Failed to create a new empty document";
+        qCritical() << "Failed to create a new empty document:" << e.what();
         vivyApp->documentStore.closeDocument(document->getUuid());
     }
 }
@@ -247,7 +247,7 @@ MainWindow::openDocument() noexcept
         addTab(new VivyDocumentView(document));
     } catch (const std::runtime_error &e) {
         qCritical() << "Failed to create the document view for" << QFileInfo(filename).baseName()
-                    << "with path" << filename;
+                    << "with path" << filename << "and error:" << e.what();
         vivyApp->documentStore.closeDocument(document->getUuid());
     }
 }
-- 
GitLab