forked from qt-creator/qt-creator
Add Q_FALLTHROUGH for Qt < 5.8
... and make use of it. With gcc 7, the new option -Wimplicit-fallthrough is introduced and added to the -Wextra set, triggering dozens of warnings in our sources. Therefore, we annotate all obviously intended fall-throughs. The ones that are still left are unclear and need to be checked by the respective maintainer. Change-Id: I44ead33cd42a4b41c28ee5fcb5a31db272710bbc Reviewed-by: Nikita Baryshnikov <nib952051@gmail.com> Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
4
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
4
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -27,6 +27,8 @@
|
||||
#include "ObjectiveCTypeQualifiers.h"
|
||||
#include "QtContextKeywords.h"
|
||||
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
@@ -442,7 +444,7 @@ bool Parser::skipUntilStatement()
|
||||
case T_AT_THROW:
|
||||
if (_languageFeatures.objCEnabled)
|
||||
return true;
|
||||
|
||||
Q_FALLTHROUGH();
|
||||
default:
|
||||
consumeToken();
|
||||
}
|
||||
|
||||
54
src/libs/utils/qtcfallthrough.h
Normal file
54
src/libs/utils/qtcfallthrough.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#ifndef Q_FALLTHROUGH
|
||||
#ifndef QT_HAS_CPP_ATTRIBUTE
|
||||
#ifdef __has_cpp_attribute
|
||||
# define QT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
||||
#else
|
||||
# define QT_HAS_CPP_ATTRIBUTE(x) 0
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__cplusplus)
|
||||
#if QT_HAS_CPP_ATTRIBUTE(fallthrough)
|
||||
# define Q_FALLTHROUGH() [[fallthrough]]
|
||||
#elif QT_HAS_CPP_ATTRIBUTE(clang::fallthrough)
|
||||
# define Q_FALLTHROUGH() [[clang::fallthrough]]
|
||||
#elif QT_HAS_CPP_ATTRIBUTE(gnu::fallthrough)
|
||||
# define Q_FALLTHROUGH() [[gnu::fallthrough]]
|
||||
#endif
|
||||
#endif
|
||||
#ifndef Q_FALLTHROUGH
|
||||
# if (defined(Q_CC_GNU) && Q_CC_GNU >= 700) && !defined(Q_CC_INTEL)
|
||||
# define Q_FALLTHROUGH() __attribute__((fallthrough))
|
||||
# else
|
||||
# define Q_FALLTHROUGH() (void)0
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@@ -239,6 +239,7 @@ HEADERS += \
|
||||
$$PWD/asconst.h \
|
||||
$$PWD/smallstringfwd.h \
|
||||
$$PWD/optional.h \
|
||||
$$PWD/qtcfallthrough.h \
|
||||
$$PWD/../3rdparty/optional/optional.hpp
|
||||
|
||||
FORMS += $$PWD/filewizardpage.ui \
|
||||
|
||||
@@ -175,6 +175,7 @@ Project {
|
||||
"proxycredentialsdialog.cpp",
|
||||
"proxycredentialsdialog.h",
|
||||
"proxycredentialsdialog.ui",
|
||||
"qtcfallthrough.h",
|
||||
"qtcassert.cpp",
|
||||
"qtcassert.h",
|
||||
"qtcolorbutton.cpp",
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
@@ -4119,7 +4120,7 @@ public:
|
||||
break;
|
||||
case FromReference:
|
||||
removeReferenceOperator(changes);
|
||||
// fallthrough intended
|
||||
Q_FALLTHROUGH();
|
||||
case FromVariable:
|
||||
convertToPointer(changes);
|
||||
break;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "compileroptionsbuilder.h"
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
@@ -201,7 +202,8 @@ static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objc
|
||||
if (!objcExt) {
|
||||
opts += QLatin1String("c++-header");
|
||||
break;
|
||||
} // else: fall-through!
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
case ProjectFile::ObjCHeader:
|
||||
case ProjectFile::ObjCXXHeader:
|
||||
opts += QLatin1String("objective-c++-header");
|
||||
@@ -211,7 +213,8 @@ static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objc
|
||||
if (!objcExt) {
|
||||
opts += QLatin1String("c");
|
||||
break;
|
||||
} // else: fall-through!
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
case ProjectFile::ObjCSource:
|
||||
opts += QLatin1String("objective-c");
|
||||
break;
|
||||
@@ -220,7 +223,8 @@ static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objc
|
||||
if (!objcExt) {
|
||||
opts += QLatin1String("c++");
|
||||
break;
|
||||
} // else: fall-through!
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
case ProjectFile::ObjCXXSource:
|
||||
opts += QLatin1String("objective-c++");
|
||||
break;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <debugger/debuggerstartparameters.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
@@ -102,7 +103,7 @@ void GdbAttachEngine::handleAttach(const DebuggerResponse &response)
|
||||
notifyEngineIll();
|
||||
break;
|
||||
}
|
||||
// if msg != "ptrace: ..." fall through
|
||||
Q_FALLTHROUGH(); // if msg != "ptrace: ..."
|
||||
default:
|
||||
showStatusMessage(tr("Failed to attach to application: %1")
|
||||
.arg(QString(response.data["msg"].data())));
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <coreplugin/messagebox.h>
|
||||
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
@@ -367,7 +368,7 @@ void GdbRemoteServerEngine::handleAttach(const DebuggerResponse &response)
|
||||
notifyInferiorSetupFailed(msgPtraceError(runParameters().startMode));
|
||||
break;
|
||||
}
|
||||
// if msg != "ptrace: ..." fall through
|
||||
Q_FALLTHROUGH(); // if msg != "ptrace: ..."
|
||||
default:
|
||||
notifyInferiorSetupFailed(response.data["msg"].data());
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <utils/treemodel.h>
|
||||
#include <utils/basetreeview.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@@ -505,7 +506,7 @@ void QmlEngine::errorMessageBoxFinished(int result)
|
||||
}
|
||||
case QMessageBox::Help: {
|
||||
HelpManager::handleHelpRequest("qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
|
||||
// fall through
|
||||
Q_FALLTHROUGH();
|
||||
}
|
||||
default:
|
||||
if (state() == InferiorRunOk) {
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "watchutils.h"
|
||||
#include "watchdata.h"
|
||||
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <string.h>
|
||||
@@ -231,8 +233,10 @@ QString formatToolTipAddress(quint64 a)
|
||||
switch (rc.size()) {
|
||||
case 16:
|
||||
rc.insert(12, colon);
|
||||
Q_FALLTHROUGH();
|
||||
case 12:
|
||||
rc.insert(8, colon);
|
||||
Q_FALLTHROUGH();
|
||||
case 8:
|
||||
rc.insert(4, colon);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
#include "utils/runextensions.h"
|
||||
#include "utils/synchronousprocess.h"
|
||||
|
||||
@@ -606,7 +607,7 @@ void IosDeviceToolHandlerPrivate::subprocessHasData()
|
||||
switch (state) {
|
||||
case NonStarted:
|
||||
qCWarning(toolHandlerLog) << "IosToolHandler unexpected state in subprocessHasData: NonStarted";
|
||||
// pass
|
||||
Q_FALLTHROUGH();
|
||||
case Starting:
|
||||
case StartedInferior:
|
||||
// read some data
|
||||
@@ -771,7 +772,7 @@ void IosDeviceToolHandlerPrivate::stop(int errorCode)
|
||||
switch (oldState) {
|
||||
case NonStarted:
|
||||
qCWarning(toolHandlerLog) << "IosToolHandler::stop() when state was NonStarted";
|
||||
// pass
|
||||
Q_FALLTHROUGH();
|
||||
case Starting:
|
||||
switch (op){
|
||||
case OpNone:
|
||||
@@ -786,7 +787,7 @@ void IosDeviceToolHandlerPrivate::stop(int errorCode)
|
||||
case OpDeviceInfo:
|
||||
break;
|
||||
}
|
||||
// pass
|
||||
Q_FALLTHROUGH();
|
||||
case StartedInferior:
|
||||
case XmlEndProcessed:
|
||||
toolExited(errorCode);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -358,6 +359,7 @@ bool FormEditorScene::event(QEvent * event)
|
||||
currentTool()->keyPressEvent(static_cast<QKeyEvent*>(event));
|
||||
return true;
|
||||
}
|
||||
Q_FALLTHROUGH();
|
||||
default: return QGraphicsScene::event(event);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,8 @@
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDockWidget>
|
||||
#include <QFileDialog>
|
||||
@@ -387,6 +389,7 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
||||
case QMessageBox::Help:
|
||||
HelpManager::handleHelpRequest(
|
||||
"qthelp://org.qt-project.qtcreator/doc/creator-debugging-qml.html");
|
||||
Q_FALLTHROUGH();
|
||||
case QMessageBox::Cancel:
|
||||
// The actual error message has already been logged.
|
||||
logState(tr("Failed to connect."));
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
// Needed for the load&save actions in the context menu
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
#include <utils/styledbar.h>
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
@@ -103,7 +104,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
|
||||
qint64 end = modelManager->traceTime()->endTime();
|
||||
d->m_zoomControl->setTrace(start, end);
|
||||
d->m_zoomControl->setRange(start, start + (end - start) / 10);
|
||||
// Fall through
|
||||
Q_FALLTHROUGH();
|
||||
}
|
||||
case QmlProfilerModelManager::Empty:
|
||||
d->m_modelProxy->setModels(d->m_suspendedModels);
|
||||
@@ -116,7 +117,7 @@ QmlProfilerTraceView::QmlProfilerTraceView(QWidget *parent, QmlProfilerViewManag
|
||||
d->m_zoomControl->clear();
|
||||
if (!d->m_suspendedModels.isEmpty())
|
||||
break; // Models are suspended already. AcquiringData was aborted.
|
||||
// Fall through
|
||||
Q_FALLTHROUGH();
|
||||
case QmlProfilerModelManager::AcquiringData:
|
||||
// Temporarily remove the models, while we're changing them
|
||||
d->m_suspendedModels = d->m_modelProxy->models();
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "scxmldocument.h"
|
||||
#include "scxmltag.h"
|
||||
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QUndoStack>
|
||||
|
||||
@@ -245,6 +247,7 @@ Qt::ItemFlags StructureModel::flags(const QModelIndex &index) const
|
||||
case Final:
|
||||
case History:
|
||||
defaultFlags |= Qt::ItemIsDragEnabled;
|
||||
Q_FALLTHROUGH();
|
||||
case Scxml:
|
||||
defaultFlags |= Qt::ItemIsDropEnabled;
|
||||
break;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
@@ -56,6 +57,7 @@ public:
|
||||
switch (v.type()) {
|
||||
case QVariant::UInt:
|
||||
m_type = QVariant::Int;
|
||||
Q_FALLTHROUGH();
|
||||
case QVariant::Int:
|
||||
m_comp.intValue = v.toInt();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user