Moc: fix narrowing conversion warnings by using iterator-based for-loop
The alternative would be to explicitly cast each list.size() to int. I think using iterators is a cleaner solution. Drive-by changes: - Give a std::pair's members better names than first/second, by using a structured binding - Port to qsizetype Pick-to: 6.6 6.5 Change-Id: Icff3126192f9813fba698d5722b209307011ca48 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
1fcbe0f6c2
commit
c88961bcf4
@ -586,13 +586,21 @@ void Generator::generateCode()
|
|||||||
fprintf(out, " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n"
|
fprintf(out, " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n"
|
||||||
" return static_cast<void*>(this);\n",
|
" return static_cast<void*>(this);\n",
|
||||||
qualifiedClassNameIdentifier.constData());
|
qualifiedClassNameIdentifier.constData());
|
||||||
for (int i = 1; i < cdef->superclassList.size(); ++i) { // for all superclasses but the first one
|
|
||||||
if (cdef->superclassList.at(i).second == FunctionDef::Private)
|
// for all superclasses but the first one
|
||||||
continue;
|
if (cdef->superclassList.size() > 1) {
|
||||||
const char *cname = cdef->superclassList.at(i).first.constData();
|
auto it = cdef->superclassList.cbegin() + 1;
|
||||||
fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
|
const auto end = cdef->superclassList.cend();
|
||||||
cname, cname);
|
for (; it != end; ++it) {
|
||||||
|
const auto &[className, access] = *it;
|
||||||
|
if (access == FunctionDef::Private)
|
||||||
|
continue;
|
||||||
|
const char *cname = className.constData();
|
||||||
|
fprintf(out, " if (!strcmp(_clname, \"%s\"))\n return static_cast< %s*>(this);\n",
|
||||||
|
cname, cname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const QList<ClassDef::Interface> &iface : std::as_const(cdef->interfaceList)) {
|
for (const QList<ClassDef::Interface> &iface : std::as_const(cdef->interfaceList)) {
|
||||||
for (qsizetype j = 0; j < iface.size(); ++j) {
|
for (qsizetype j = 0; j < iface.size(); ++j) {
|
||||||
fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData());
|
fprintf(out, " if (!strcmp(_clname, %s))\n return ", iface.at(j).interfaceId.constData());
|
||||||
@ -1010,10 +1018,11 @@ void Generator::generateStaticMetacall()
|
|||||||
Q_ASSERT(!f.isPrivateSignal); // That would be a strange ctor indeed
|
Q_ASSERT(!f.isPrivateSignal); // That would be a strange ctor indeed
|
||||||
int offset = 1;
|
int offset = 1;
|
||||||
|
|
||||||
int argsCount = f.arguments.size();
|
const auto begin = f.arguments.cbegin();
|
||||||
for (int j = 0; j < argsCount; ++j) {
|
const auto end = f.arguments.cend();
|
||||||
const ArgumentDef &a = f.arguments.at(j);
|
for (auto it = begin; it != end; ++it) {
|
||||||
if (j)
|
const ArgumentDef &a = *it;
|
||||||
|
if (it != begin)
|
||||||
fprintf(out, ",");
|
fprintf(out, ",");
|
||||||
fprintf(out, "(*reinterpret_cast<%s>(_a[%d]))",
|
fprintf(out, "(*reinterpret_cast<%s>(_a[%d]))",
|
||||||
a.typeNameForCast.constData(), offset++);
|
a.typeNameForCast.constData(), offset++);
|
||||||
@ -1085,16 +1094,17 @@ void Generator::generateStaticMetacall()
|
|||||||
if (f.isRawSlot) {
|
if (f.isRawSlot) {
|
||||||
fprintf(out, "QMethodRawArguments{ _a }");
|
fprintf(out, "QMethodRawArguments{ _a }");
|
||||||
} else {
|
} else {
|
||||||
int argsCount = f.arguments.size();
|
const auto begin = f.arguments.cbegin();
|
||||||
for (int j = 0; j < argsCount; ++j) {
|
const auto end = f.arguments.cend();
|
||||||
const ArgumentDef &a = f.arguments.at(j);
|
for (auto it = begin; it != end; ++it) {
|
||||||
if (j)
|
const ArgumentDef &a = *it;
|
||||||
|
if (it != begin)
|
||||||
fprintf(out, ",");
|
fprintf(out, ",");
|
||||||
fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))",a.typeNameForCast.constData(), offset++);
|
fprintf(out, "(*reinterpret_cast< %s>(_a[%d]))",a.typeNameForCast.constData(), offset++);
|
||||||
isUsed_a = true;
|
isUsed_a = true;
|
||||||
}
|
}
|
||||||
if (f.isPrivateSignal) {
|
if (f.isPrivateSignal) {
|
||||||
if (argsCount > 0)
|
if (!f.arguments.isEmpty())
|
||||||
fprintf(out, ", ");
|
fprintf(out, ", ");
|
||||||
fprintf(out, "%s", "QPrivateSignal()");
|
fprintf(out, "%s", "QPrivateSignal()");
|
||||||
}
|
}
|
||||||
@ -1155,15 +1165,16 @@ void Generator::generateStaticMetacall()
|
|||||||
fprintf(out, " {\n");
|
fprintf(out, " {\n");
|
||||||
fprintf(out, " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData());
|
fprintf(out, " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData());
|
||||||
|
|
||||||
int argsCount = f.arguments.size();
|
const auto begin = f.arguments.cbegin();
|
||||||
for (int j = 0; j < argsCount; ++j) {
|
const auto end = f.arguments.cend();
|
||||||
const ArgumentDef &a = f.arguments.at(j);
|
for (auto it = begin; it != end; ++it) {
|
||||||
if (j)
|
const ArgumentDef &a = *it;
|
||||||
|
if (it != begin)
|
||||||
fprintf(out, ", ");
|
fprintf(out, ", ");
|
||||||
fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
|
fprintf(out, "%s", QByteArray(a.type.name + ' ' + a.rightType).constData());
|
||||||
}
|
}
|
||||||
if (f.isPrivateSignal) {
|
if (f.isPrivateSignal) {
|
||||||
if (argsCount > 0)
|
if (!f.arguments.isEmpty())
|
||||||
fprintf(out, ", ");
|
fprintf(out, ", ");
|
||||||
fprintf(out, "%s", "QPrivateSignal");
|
fprintf(out, "%s", "QPrivateSignal");
|
||||||
}
|
}
|
||||||
@ -1420,9 +1431,11 @@ void Generator::generateSignal(FunctionDef *def,int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int offset = 1;
|
int offset = 1;
|
||||||
for (int j = 0; j < def->arguments.size(); ++j) {
|
const auto begin = def->arguments.cbegin();
|
||||||
const ArgumentDef &a = def->arguments.at(j);
|
const auto end = def->arguments.cend();
|
||||||
if (j)
|
for (auto it = begin; it != end; ++it) {
|
||||||
|
const ArgumentDef &a = *it;
|
||||||
|
if (it != begin)
|
||||||
fputs(", ", out);
|
fputs(", ", out);
|
||||||
if (a.type.name.size())
|
if (a.type.name.size())
|
||||||
fputs(a.type.name.constData(), out);
|
fputs(a.type.name.constData(), out);
|
||||||
|
@ -618,17 +618,20 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
|
|||||||
HashHash
|
HashHash
|
||||||
} mode = Normal;
|
} mode = Normal;
|
||||||
|
|
||||||
for (int i = 0; i < macro.symbols.size(); ++i) {
|
const auto end = macro.symbols.cend();
|
||||||
const Symbol &s = macro.symbols.at(i);
|
auto it = macro.symbols.cbegin();
|
||||||
|
const auto lastSym = std::prev(macro.symbols.cend(), !macro.symbols.isEmpty() ? 1 : 0);
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
const Symbol &s = *it;
|
||||||
if (s.token == HASH || s.token == PP_HASHHASH) {
|
if (s.token == HASH || s.token == PP_HASHHASH) {
|
||||||
mode = (s.token == HASH ? Hash : HashHash);
|
mode = (s.token == HASH ? Hash : HashHash);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int index = macro.arguments.indexOf(s);
|
const qsizetype index = macro.arguments.indexOf(s);
|
||||||
if (mode == Normal) {
|
if (mode == Normal) {
|
||||||
if (index >= 0 && index < arguments.size()) {
|
if (index >= 0 && index < arguments.size()) {
|
||||||
// each argument undoergoes macro expansion if it's not used as part of a # or ##
|
// each argument undoergoes macro expansion if it's not used as part of a # or ##
|
||||||
if (i == macro.symbols.size() - 1 || macro.symbols.at(i + 1).token != PP_HASHHASH) {
|
if (it == lastSym || std::next(it)->token != PP_HASHHASH) {
|
||||||
Symbols arg = arguments.at(index);
|
Symbols arg = arguments.at(index);
|
||||||
qsizetype idx = 1;
|
qsizetype idx = 1;
|
||||||
macroExpand(&expansion, that, arg, idx, lineNum, false, symbols.excludeSymbols());
|
macroExpand(&expansion, that, arg, idx, lineNum, false, symbols.excludeSymbols());
|
||||||
|
Loading…
Reference in New Issue
Block a user