From ebe23a694b506f530c043866d7a59b72b8be31df Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 2 Oct 2018 15:23:06 +0200 Subject: [PATCH] Fix GCC7 fallthrough warnings --- src/blackcore/aircraftmatcher.cpp | 3 +- .../components/dbmappingcomponent.cpp | 2 ++ .../models/aircraftmodellistmodel.cpp | 2 ++ src/blackgui/models/distributorlistmodel.cpp | 3 ++ src/blackmisc/aviation/aircraftsituation.cpp | 2 ++ src/blackmisc/db/updateinfo.cpp | 2 +- src/blackmisc/fallthrough.h | 33 +++++++++++++++++++ src/blackmisc/logpattern.cpp | 6 ++++ src/blackmisc/network/remotefile.cpp | 4 +-- src/xswiftbus/traffic.cpp | 5 ++- 10 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/blackmisc/fallthrough.h diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index 22b9fecbd..ebaf0e577 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -10,6 +10,7 @@ #include "blackcore/aircraftmatcher.h" #include "blackcore/application.h" #include "blackcore/webdataservices.h" +#include "blackmisc/fallthrough.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/matchingutils.h" #include "blackmisc/aviation/aircrafticaocode.h" @@ -226,7 +227,7 @@ namespace BlackCore matchedModel = candidates.minOrderOrDefault(); break; } - // [[clang::fallthrough]]; + BLACK_FALLTHROUGH; case CAircraftMatcherSetup::PickFirst: default: usedStrategy = CAircraftMatcherSetup::PickFirst; // re-assigned if fall-through diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 26a8da68f..631d9f969 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -30,6 +30,7 @@ #include "blackgui/shortcut.h" #include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/livery.h" +#include "blackmisc/fallthrough.h" #include "blackmisc/icons.h" #include "blackmisc/logmessage.h" #include "blackmisc/network/authenticateduser.h" @@ -612,6 +613,7 @@ namespace BlackGui { // fall thru intended this->formatVPilotView(); + BLACK_FALLTHROUGH; } default: { diff --git a/src/blackgui/models/aircraftmodellistmodel.cpp b/src/blackgui/models/aircraftmodellistmodel.cpp index 38960b01a..5b958cf98 100644 --- a/src/blackgui/models/aircraftmodellistmodel.cpp +++ b/src/blackgui/models/aircraftmodellistmodel.cpp @@ -10,6 +10,7 @@ #include "blackgui/models/aircraftmodellistmodel.h" #include "blackgui/models/columnformatters.h" #include "blackgui/models/columns.h" +#include "blackmisc/fallthrough.h" #include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/airlineicaocode.h" #include "blackmisc/aviation/livery.h" @@ -75,6 +76,7 @@ namespace BlackGui case OwnModelSet: // intentional fall thru m_columns.addColumn(CColumn::orderColumn()); + BLACK_FALLTHROUGH; case OwnAircraftModelMappingTool: case StashModel: diff --git a/src/blackgui/models/distributorlistmodel.cpp b/src/blackgui/models/distributorlistmodel.cpp index f6cf6240c..a85806923 100644 --- a/src/blackgui/models/distributorlistmodel.cpp +++ b/src/blackgui/models/distributorlistmodel.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "blackmisc/fallthrough.h" #include "blackgui/models/columns.h" #include "blackgui/models/distributorlistmodel.h" #include "blackmisc/db/datastore.h" @@ -46,6 +47,7 @@ namespace BlackGui { case NormalWithOrder: this->m_columns.addColumn(CColumn::orderColumn()); + BLACK_FALLTHROUGH; case NotSet: case Normal: { @@ -64,6 +66,7 @@ namespace BlackGui case MinimalWithOrder: this->m_columns.addColumn(CColumn::orderColumn()); + BLACK_FALLTHROUGH; case Minimal: { this->m_columns.addColumn(CColumn::standardString("key", CDistributor::IndexDbStringKey)); diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 48f80d5b2..c67c1e504 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "blackmisc/fallthrough.h" #include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/aviation/aircraftsituation.h" #include "blackmisc/aviation/aircraftsituationchange.h" @@ -393,6 +394,7 @@ namespace BlackMisc const int c = Compare::compare(this->getGroundElevationInfo(), compareValue.getGroundElevationInfo()); if (c != 0) { return c; } // fall through, compare flag + BLACK_FALLTHROUGH; } case IndexGroundElevationInfoTransferred: return Compare::compare(m_isElvInfoTransferred, compareValue.m_isElvInfoTransferred); case IndexCanLikelySkipNearGroundInterpolation: return Compare::compare(this->canLikelySkipNearGroundInterpolation(), compareValue.canLikelySkipNearGroundInterpolation()); diff --git a/src/blackmisc/db/updateinfo.cpp b/src/blackmisc/db/updateinfo.cpp index 16a2433bb..6242016af 100644 --- a/src/blackmisc/db/updateinfo.cpp +++ b/src/blackmisc/db/updateinfo.cpp @@ -113,7 +113,7 @@ namespace BlackMisc switch (i) { case IndexArtifactsPilotClient: return CVariant::fromValue(m_artifactsPilotClient); - case IndexArtifactsXSwiftBus: CVariant::fromValue(m_artifactsXSwiftBus); + case IndexArtifactsXSwiftBus: return CVariant::fromValue(m_artifactsXSwiftBus); case IndexDistributions: return CVariant::fromValue(m_distributions); default: return CValueObject::propertyByIndex(index); } diff --git a/src/blackmisc/fallthrough.h b/src/blackmisc/fallthrough.h new file mode 100644 index 000000000..d5ff744a6 --- /dev/null +++ b/src/blackmisc/fallthrough.h @@ -0,0 +1,33 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_FALLTHROUGH_H +#define BLACKMISC_FALLTHROUGH_H + +#include + +//! \cond + +// MSVC2017: [[fallthrough]] supported but only enabled with /std:c++17 +// GCC7+: [[gnu::fallthrough]] for C++11/14, [[fallthrough]] for C++17 +// XCode: Does not seem to work in current configuration + +#if defined(Q_CC_GNU) && Q_CC_GNU > 700 + #if __has_cpp_attribute(fallthrough) + #define BLACK_FALLTHROUGH [[gnu::fallthrough]] + #endif +#else + #define BLACK_FALLTHROUGH +#endif + +//! \endcond + +#endif diff --git a/src/blackmisc/logpattern.cpp b/src/blackmisc/logpattern.cpp index 51229a7ac..ed70ec38c 100644 --- a/src/blackmisc/logpattern.cpp +++ b/src/blackmisc/logpattern.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "blackmisc/fallthrough.h" #include "blackmisc/logcategory.h" #include "blackmisc/logcategorylist.h" #include "blackmisc/logpattern.h" @@ -155,8 +156,11 @@ namespace BlackMisc // there are deliberately no break statements in this switch block default: case CStatusMessage::SeverityDebug: result.m_severities.insert(CStatusMessage::SeverityDebug); + BLACK_FALLTHROUGH; case CStatusMessage::SeverityInfo: result.m_severities.insert(CStatusMessage::SeverityInfo); + BLACK_FALLTHROUGH; case CStatusMessage::SeverityWarning: result.m_severities.insert(CStatusMessage::SeverityWarning); + BLACK_FALLTHROUGH; case CStatusMessage::SeverityError: result.m_severities.insert(CStatusMessage::SeverityError); } return result; @@ -273,6 +277,7 @@ namespace BlackMisc case EndsWith: return std::all_of(m_strings.begin(), m_strings.end(), [ & ](const QString & s) { return s.endsWith(other.getSuffix()); }); case Contains: return std::all_of(m_strings.begin(), m_strings.end(), [ & ](const QString & s) { return s.contains(other.getSubstring()); }); default: ; + BLACK_FALLTHROUGH ; } case AllOf: switch (other.m_strategy) @@ -284,6 +289,7 @@ namespace BlackMisc case EndsWith: return std::any_of(m_strings.begin(), m_strings.end(), [ & ](const QString & s) { return s.endsWith(other.getSuffix()); }); case Contains: return std::any_of(m_strings.begin(), m_strings.end(), [ & ](const QString & s) { return s.contains(other.getSubstring()); }); default: ; + BLACK_FALLTHROUGH ; } case StartsWith: switch (other.m_strategy) diff --git a/src/blackmisc/network/remotefile.cpp b/src/blackmisc/network/remotefile.cpp index 72e3de83c..75eb16d26 100644 --- a/src/blackmisc/network/remotefile.cpp +++ b/src/blackmisc/network/remotefile.cpp @@ -113,8 +113,8 @@ namespace BlackMisc { case IndexName: this->setName(variant.value()); break; case IndexDescription: this->setDescription(variant.value()); break; - case IndexUrl: m_url.setPropertyByIndex(index.copyFrontRemoved(), variant); - case IndexSize: this->setSize(variant.toInt()); + case IndexUrl: m_url.setPropertyByIndex(index.copyFrontRemoved(), variant); break; + case IndexSize: this->setSize(variant.toInt()); break; default: CValueObject::setPropertyByIndex(index, variant); break; } } diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 34be18474..22514f55d 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -792,6 +792,7 @@ namespace XSwiftBus } else { return xpmpData_Unchanged; } } + break; case xpmpDataType_Radar: if (plane->hasXpdr) @@ -805,10 +806,8 @@ namespace XSwiftBus } else { return xpmpData_Unchanged; } } - else { return xpmpData_Unavailable; } - - default: return xpmpData_Unavailable; } + return xpmpData_Unavailable; } int CTraffic::orbitPlaneFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon)