From 08535a7e6308c688924ea503a00cb807812197a8 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Fri, 4 Feb 2022 12:15:45 +0100 Subject: [PATCH] Make share/qtcreator/cplusplus/examples compilable Builds now, but does not link (which is fine). And unrelated, unintentional warnings were removed. Change-Id: I6ece33933bc20e6e36fb3859de7c2b774b0e67d5 Reviewed-by: Reviewed-by: Cristian Adam --- .../cplusplus/examples/CMakeLists.txt | 7 ++++-- .../cplusplus/examples/clazy_example.cpp | 8 +------ .../qtcreator/cplusplus/examples/icontest.cpp | 22 ++++++++++--------- .../cplusplus/examples/tidy_example.cpp | 9 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/share/qtcreator/cplusplus/examples/CMakeLists.txt b/share/qtcreator/cplusplus/examples/CMakeLists.txt index cafabb6f7cb..004deeded3e 100644 --- a/share/qtcreator/cplusplus/examples/CMakeLists.txt +++ b/share/qtcreator/cplusplus/examples/CMakeLists.txt @@ -11,7 +11,10 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Gui Widgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED) + +set_property(SOURCE clazy_example.cpp icontest.cpp PROPERTY SKIP_AUTOMOC ON) add_executable(examples clazy_example.cpp @@ -20,4 +23,4 @@ add_executable(examples tidy_example.h ) -target_link_libraries(examples PRIVATE Qt5::Widgets) +target_link_libraries(examples PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) diff --git a/share/qtcreator/cplusplus/examples/clazy_example.cpp b/share/qtcreator/cplusplus/examples/clazy_example.cpp index 3fef3cb8a5a..bf1cbe2e61c 100644 --- a/share/qtcreator/cplusplus/examples/clazy_example.cpp +++ b/share/qtcreator/cplusplus/examples/clazy_example.cpp @@ -113,9 +113,6 @@ TestObject::TestObject() for (auto obj : list) { } - // -Wclazy-qdatetime-utc - QDateTime::currentDateTime().toTime_t(); - // -Wclazy-qfileinfo-exists // -Wclazy-qstring-allocations QFileInfo("filename").exists(); @@ -134,8 +131,5 @@ TestObject::TestObject() str.mid(5).toInt(&ok); // -Wclazy-qstring-arg - QString("%1 %2").arg("1").arg("2"); + (void) QString("%1 %2").arg("1").arg("2"); } - -// Note: A fatal error like an unresolved include will make clazy stop emitting any diagnostics. -// #include "clazy_example.moc" diff --git a/share/qtcreator/cplusplus/examples/icontest.cpp b/share/qtcreator/cplusplus/examples/icontest.cpp index 2aea615fd24..764c920b938 100644 --- a/share/qtcreator/cplusplus/examples/icontest.cpp +++ b/share/qtcreator/cplusplus/examples/icontest.cpp @@ -27,12 +27,13 @@ #define Macro -class Class { +class Class : public QObject { Q_OBJECT + public: - Q_PROPERTY(bool property READ readProperty CONSTANT); - void publicFunction(); - void static publicStaticFunction(); + Q_PROPERTY(int property READ publicStaticFunction CONSTANT) + int publicFunction() { return 0; } + int static publicStaticFunction() { return 0; } template void publicTemplateFunction(); template void static publicStaticTemplateFunction(); @@ -43,8 +44,8 @@ signals: void signal(); public slots: - void publicSlot(); - template void publicTemplateSlot(); + void publicSlot() {} + // template void publicTemplateSlot() {} protected: void protectedFunction(); @@ -56,8 +57,8 @@ protected: int static protectedStaticVariable; protected slots: - void protectedSlot(); - template void protectedTemplateSlot(); + void protectedSlot() {} + // template void protectedTemplateSlot() {} private: void privateFunction(); @@ -67,9 +68,10 @@ private: template void static privateStaticTemplateFunction(); private slots: - void privateSlot(); - template void privateTemplateSlot(); + void privateSlot() {} + // template void privateTemplateSlot() {} +private: int privateVariable; int static privateStaticVariable; }; diff --git a/share/qtcreator/cplusplus/examples/tidy_example.cpp b/share/qtcreator/cplusplus/examples/tidy_example.cpp index dc921114ea1..0a814411ce6 100644 --- a/share/qtcreator/cplusplus/examples/tidy_example.cpp +++ b/share/qtcreator/cplusplus/examples/tidy_example.cpp @@ -71,7 +71,7 @@ public: // misc-noexcept-move-constructor // misc-unconventional-assign-operator // misc-unused-parameters - Base operator=(Base &¶m) {} + Base operator=(Base &¶m) { return {}; } virtual int function() { // modernize-use-nullptr @@ -116,7 +116,7 @@ void afterMove(Base &&base) Base moved(std::move(base)); // misc-use-after-move - base.value; + (void) base.value; } // google-runtime-references @@ -144,7 +144,7 @@ public: auto b = {0.5f, 0.5f, 0.5f, 0.5f}; // misc-fold-init-type - std::accumulate(std::begin(b), std::end(b), 0); + (void) std::accumulate(std::begin(b), std::end(b), 0); // google-readability-casting, misc-incorrect-roundings auto c = (int)(getDouble() + 0.5); @@ -197,6 +197,7 @@ public: std::system("echo "); // cert-err52-cpp setjmp(nullptr); + return 0; } // google-default-arguments @@ -251,7 +252,7 @@ int main() // modernize-loop-convert for (int i = 0; i < 3; ++i) { // cppcoreguidelines-pro-bounds-constant-array-index - arr[i]; + (void) arr[i]; } std::vector> w;