summaryrefslogtreecommitdiffstats
path: root/src/tools/moc
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-05-18 18:24:00 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-05-28 01:18:49 +0300
commit10510c0405f6aff26a623e9d679373abc2c7e1ab (patch)
treef60f417dd71b5e06a5a868ac459de1fb6c677ba9 /src/tools/moc
parent26dd7fe4edb8ed39ebf12cae874eb89e46ff9067 (diff)
Moc: fix narrowing conversion warnings with iterators/algorithms
Drive-by change: check a QList isn't empty before using first() Pick-to: 6.5 Change-Id: I24171d17244ae96ad5779d721c65d33e5489f5f3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/tools/moc')
-rw-r--r--src/tools/moc/moc.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index bcdf5b48d3..3766e7f916 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -1070,12 +1070,13 @@ static QByteArrayList requiredQtContainers(const QList<ClassDef> &classes)
void Moc::generate(FILE *out, FILE *jsonOutput)
{
- QByteArray fn = filename;
- int i = filename.size()-1;
- while (i > 0 && filename.at(i - 1) != '/' && filename.at(i - 1) != '\\')
- --i; // skip path
- if (i >= 0)
- fn = filename.mid(i);
+ QByteArrayView fn = QByteArrayView(filename);
+
+ auto isSlash = [](char ch) { return ch == '/' || ch == '\\'; };
+ auto rit = std::find_if(fn.crbegin(), fn.crend(), isSlash);
+ if (rit != fn.crend())
+ fn = fn.last(rit - fn.crbegin());
+
fprintf(out, "/****************************************************************************\n"
"** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
fprintf(out, "** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , mocOutputRevision, QT_VERSION_STR);
@@ -1141,7 +1142,7 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
fprintf(out, "QT_WARNING_DISABLE_GCC(\"-Wuseless-cast\")\n");
fputs("", out);
- for (i = 0; i < classList.size(); ++i) {
+ for (int i = 0; i < classList.size(); ++i) {
Generator generator(&classList[i], metaTypes, knownQObjectClasses, knownGadgets, out, requireCompleteTypes);
generator.generateCode();
}
@@ -1818,8 +1819,19 @@ void Moc::checkSuperClasses(ClassDef *def)
#endif
return;
}
- for (int i = 1; i < def->superclassList.size(); ++i) {
- const QByteArray superClass = def->superclassList.at(i).first;
+
+ auto isRegisteredInterface = [&def](QByteArrayView super) {
+ auto matchesSuperClass = [&super](const auto &ifaces) {
+ return !ifaces.isEmpty() && ifaces.first().className == super;
+ };
+ return std::any_of(def->interfaceList.cbegin(), def->interfaceList.cend(), matchesSuperClass);
+ };
+
+ const auto end = def->superclassList.cend();
+ auto it = std::next(def->superclassList.cbegin(),
+ !def->superclassList.isEmpty() ? 1 : 0);
+ for (; it != end; ++it) {
+ const QByteArray &superClass = it->first;
if (knownQObjectClasses.contains(superClass)) {
const QByteArray msg
= "Class "
@@ -1833,14 +1845,7 @@ void Moc::checkSuperClasses(ClassDef *def)
}
if (interface2IdMap.contains(superClass)) {
- bool registeredInterface = false;
- for (int i = 0; i < def->interfaceList.size(); ++i)
- if (def->interfaceList.at(i).constFirst().className == superClass) {
- registeredInterface = true;
- break;
- }
-
- if (!registeredInterface) {
+ if (!isRegisteredInterface(superClass)) {
const QByteArray msg
= "Class "
+ def->classname