I enabled the compiler flag "-Wshadow" on a Qt project. Now I get a warning for every nested foreach loop in the project. It seems, that the foreach macro uses an identifier which is duplicated in a nested foreach loop.
Quick example:
QStringList listA, listB;
foreach (QString a, listA) {
foreach (QString b, listB) {
qDebug() << a << b;
}
}
Compiler output:
Test.cpp:46:9: warning: declaration shadows a local variable [-Wshadow]
foreach (QString b, listB) {
^
/usr/include/qt5/QtCore/qglobal.h:911:21: note: expanded from macro 'foreach'
# define foreach Q_FOREACH
^
/usr/include/qt5/QtCore/qglobal.h:857:47: note: expanded from macro 'Q_FOREACH'
for (QForeachContainer<__typeof__(container)> _container_(container); \
^
Test.cpp:45:5: note: previous declaration is here
foreach (QString a, listA) {
^
/usr/include/qt5/QtCore/qglobal.h:911:21: note: expanded from macro 'foreach'
# define foreach Q_FOREACH
^
/usr/include/qt5/QtCore/qglobal.h:857:47: note: expanded from macro 'Q_FOREACH'
for (QForeachContainer<__typeof__(container)> _container_(container); \
^
Is there a way to enable -Wshadow but suppress the warnings from nested foreach?