llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.87k stars 11.93k forks source link

Create qt-foreach-convert check #27508

Open LegalizeAdulthood opened 8 years ago

LegalizeAdulthood commented 8 years ago
Bugzilla Link 27134
Version unspecified
OS Windows NT
CC @chgans,@EugeneZelenko

Extended Description

There are a number of checks that are specific to usage of the Qt library.

In the Qt4 library, they provide a Q_FOREACH construct similar to BOOST_FOREACH. Replace iterating loops with Q_FOREACH, like so:

QStringList files(getFiles());
for (int i = 0; i < files.count(); ++i)
{
  QString file(files[i]);
  // do something with file, but not index i
}

with

Q_FOREACH(QString file, files)
{
}

It's possible that in Qt5 they have extended this further to allow C++11 range for loops to be used directly on the QStringList and other QList<> types. If so, then normal range-based for loops should be preferred over the Q_FOREACH macro.

There are still many Qt code bases that would benefit from Q_FOREACH however.

It may also be possible to transform loops using Qt's java style iterator classes into Q_FOREACH.

chgans commented 5 years ago

Hi Eugene,

What was the reactions from Clazy's author? I agree that it would be nice to have a new 'qt' category, and clazy has a nice collection of checks. They have some that are not qt specific tho.

EugeneZelenko commented 8 years ago

There are https://github.com/KDE/clazy which deals with Qt-related stuff. I already suggested authors to port checks to Clang-tidy.