aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-07-14 13:44:33 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2017-07-17 07:51:23 +0000
commitbe2b3c91ae4ddb97c35237da11b350c99cc6fd3b (patch)
tree30e177b9f5a019b639966a13834c2d7fd2196594 /src
parentc9301e80bb960ba5df93fdd22932257542693154 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/libs/3rdparty/cplusplus/Parser.cpp4
-rw-r--r--src/libs/utils/qtcfallthrough.h54
-rw-r--r--src/libs/utils/utils-lib.pri1
-rw-r--r--src/libs/utils/utils.qbs1
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp3
-rw-r--r--src/plugins/cpptools/compileroptionsbuilder.cpp10
-rw-r--r--src/plugins/debugger/gdb/attachgdbadapter.cpp3
-rw-r--r--src/plugins/debugger/gdb/remotegdbserveradapter.cpp3
-rw-r--r--src/plugins/debugger/qml/qmlengine.cpp3
-rw-r--r--src/plugins/debugger/watchutils.cpp4
-rw-r--r--src/plugins/ios/iostoolhandler.cpp7
-rw-r--r--src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp2
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.cpp3
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertraceview.cpp5
-rw-r--r--src/plugins/scxmleditor/common/structuremodel.cpp3
-rw-r--r--src/plugins/vcsbase/vcsbaseclientsettings.cpp2
16 files changed, 95 insertions, 13 deletions
diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp
index 8754206a0b5..16f351077a1 100644
--- a/src/libs/3rdparty/cplusplus/Parser.cpp
+++ b/src/libs/3rdparty/cplusplus/Parser.cpp
@@ -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();
}
diff --git a/src/libs/utils/qtcfallthrough.h b/src/libs/utils/qtcfallthrough.h
new file mode 100644
index 00000000000..6eba622837f
--- /dev/null
+++ b/src/libs/utils/qtcfallthrough.h
@@ -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
diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri
index bfc9d6084e1..3a6aa0a09af 100644
--- a/src/libs/utils/utils-lib.pri
+++ b/src/libs/utils/utils-lib.pri
@@ -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 \
diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs
index 559129df164..6d68683fdd5 100644
--- a/src/libs/utils/utils.qbs
+++ b/src/libs/utils/utils.qbs
@@ -175,6 +175,7 @@ Project {
"proxycredentialsdialog.cpp",
"proxycredentialsdialog.h",
"proxycredentialsdialog.ui",
+ "qtcfallthrough.h",
"qtcassert.cpp",
"qtcassert.h",
"qtcolorbutton.cpp",
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 67d360c3bb5..640fa794ef0 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.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;
diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp
index 8f5fd397fb7..170279c9b8f 100644
--- a/src/plugins/cpptools/compileroptionsbuilder.cpp
+++ b/src/plugins/cpptools/compileroptionsbuilder.cpp
@@ -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;
diff --git a/src/plugins/debugger/gdb/attachgdbadapter.cpp b/src/plugins/debugger/gdb/attachgdbadapter.cpp
index 11566a51be5..519647d7035 100644
--- a/src/plugins/debugger/gdb/attachgdbadapter.cpp
+++ b/src/plugins/debugger/gdb/attachgdbadapter.cpp
@@ -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())));
diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
index a36aa11bef0..cf55a82dc6b 100644
--- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
+++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp
@@ -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());
}
diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp
index 87b4a039d05..0a0ed1d5166 100644
--- a/src/plugins/debugger/qml/qmlengine.cpp
+++ b/src/plugins/debugger/qml/qmlengine.cpp
@@ -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) {
diff --git a/src/plugins/debugger/watchutils.cpp b/src/plugins/debugger/watchutils.cpp
index f6e8dfeb456..2275807d22c 100644
--- a/src/plugins/debugger/watchutils.cpp
+++ b/src/plugins/debugger/watchutils.cpp
@@ -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);
}
diff --git a/src/plugins/ios/iostoolhandler.cpp b/src/plugins/ios/iostoolhandler.cpp
index f2afa714337..317c1f6f594 100644
--- a/src/plugins/ios/iostoolhandler.cpp
+++ b/src/plugins/ios/iostoolhandler.cpp
@@ -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);
diff --git a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
index 950028bf3be..3601db17535 100644
--- a/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
+++ b/src/plugins/qmldesigner/components/formeditor/formeditorscene.cpp
@@ -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);
}
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index 227b6dff0b7..e246bf885c0 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -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."));
diff --git a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp
index 8519d124223..a2a00b4f983 100644
--- a/src/plugins/qmlprofiler/qmlprofilertraceview.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertraceview.cpp
@@ -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();
diff --git a/src/plugins/scxmleditor/common/structuremodel.cpp b/src/plugins/scxmleditor/common/structuremodel.cpp
index f7b2e563e98..5f63319c167 100644
--- a/src/plugins/scxmleditor/common/structuremodel.cpp
+++ b/src/plugins/scxmleditor/common/structuremodel.cpp
@@ -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;
diff --git a/src/plugins/vcsbase/vcsbaseclientsettings.cpp b/src/plugins/vcsbase/vcsbaseclientsettings.cpp
index 35c2a7c1199..ab67910c2f5 100644
--- a/src/plugins/vcsbase/vcsbaseclientsettings.cpp
+++ b/src/plugins/vcsbase/vcsbaseclientsettings.cpp
@@ -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;