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: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Alessandro Portale
2022-02-04 12:15:45 +01:00
parent 96ec295fc6
commit 08535a7e63
4 changed files with 23 additions and 23 deletions

View File

@@ -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)

View File

@@ -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"

View File

@@ -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<int> void publicTemplateFunction();
template<int> void static publicStaticTemplateFunction();
@@ -43,8 +44,8 @@ signals:
void signal();
public slots:
void publicSlot();
template<int> void publicTemplateSlot();
void publicSlot() {}
// template<int> void publicTemplateSlot() {}
protected:
void protectedFunction();
@@ -56,8 +57,8 @@ protected:
int static protectedStaticVariable;
protected slots:
void protectedSlot();
template<int> void protectedTemplateSlot();
void protectedSlot() {}
// template<int> void protectedTemplateSlot() {}
private:
void privateFunction();
@@ -67,9 +68,10 @@ private:
template<int> void static privateStaticTemplateFunction();
private slots:
void privateSlot();
template<int> void privateTemplateSlot();
void privateSlot() {}
// template<int> void privateTemplateSlot() {}
private:
int privateVariable;
int static privateStaticVariable;
};

View File

@@ -71,7 +71,7 @@ public:
// misc-noexcept-move-constructor
// misc-unconventional-assign-operator
// misc-unused-parameters
Base operator=(Base &&param) {}
Base operator=(Base &&param) { 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<std::pair<int, int>> w;