diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-05-18 19:29:46 +0300 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-06-20 06:53:52 +0000 |
commit | c88961bcf4779933457bc8965b1281f83165a12d (patch) | |
tree | 6f81701f2998ab69f1ab7158609cb3f12d7b3e6b /src/tools/moc/preprocessor.cpp | |
parent | 1fcbe0f6c24eff66add23bcc6212451a87d64c05 (diff) |
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>
Diffstat (limited to 'src/tools/moc/preprocessor.cpp')
-rw-r--r-- | src/tools/moc/preprocessor.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index 0afadce2b5..e51a005935 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -618,17 +618,20 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym HashHash } mode = Normal; - for (int i = 0; i < macro.symbols.size(); ++i) { - const Symbol &s = macro.symbols.at(i); + const auto end = macro.symbols.cend(); + 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) { mode = (s.token == HASH ? Hash : HashHash); continue; } - int index = macro.arguments.indexOf(s); + const qsizetype index = macro.arguments.indexOf(s); if (mode == Normal) { if (index >= 0 && index < arguments.size()) { // 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); qsizetype idx = 1; macroExpand(&expansion, that, arg, idx, lineNum, false, symbols.excludeSymbols()); |