Skip to content

Commit

Permalink
[travis] Warn on unintentional switch fallthrough
Browse files Browse the repository at this point in the history
Intentional fallthrough should be annotated with

"FALLTHROUGH;"
  • Loading branch information
nyalldawson committed Jan 25, 2016
1 parent f6c0d8d commit cf3c55b
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ci/travis/linux/install.sh
@@ -1,6 +1,8 @@
mkdir build
cd build

CLANG_WARNINGS="-Wimplicit-fallthrough"

cmake -DWITH_SERVER=ON \
-DWITH_STAGED_PLUGINS=ON \
-DWITH_GRASS=ON \
Expand All @@ -13,4 +15,5 @@ cmake -DWITH_SERVER=ON \
-DWITH_PYSPATIALITE=ON \
-DGRASS_PREFIX7=/usr/lib/grass70 \
-DGRASS_INCLUDE_DIR7=/usr/lib/grass70/include \
-DCXX_EXTRA_FLAGS="$CLANG_WARNINGS" \
..
2 changes: 2 additions & 0 deletions src/analysis/interpolation/qgsinterpolator.cpp
Expand Up @@ -117,6 +117,7 @@ int QgsInterpolator::addVerticesToCache( const QgsGeometry *geom, bool zCoord, d
case QGis::WKBPoint25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBPoint:
{
currentWkbPtr >> theVertex.x >> theVertex.y;
Expand All @@ -134,6 +135,7 @@ int QgsInterpolator::addVerticesToCache( const QgsGeometry *geom, bool zCoord, d
case QGis::WKBLineString25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBLineString:
{
int nPoints;
Expand Down
6 changes: 6 additions & 0 deletions src/analysis/interpolation/qgstininterpolator.cpp
Expand Up @@ -208,6 +208,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
{
case QGis::WKBPoint25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBPoint:
{
currentWkbPtr >> x >> y;
Expand All @@ -228,6 +229,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
}
case QGis::WKBMultiPoint25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBMultiPoint:
{
int nPoints;
Expand All @@ -249,6 +251,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
}
case QGis::WKBLineString25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBLineString:
{
if ( type != POINTS )
Expand Down Expand Up @@ -288,6 +291,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
}
case QGis::WKBMultiLineString25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBMultiLineString:
{
int nLines;
Expand Down Expand Up @@ -331,6 +335,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT
}
case QGis::WKBPolygon25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBPolygon:
{
int nRings;
Expand Down Expand Up @@ -376,6 +381,7 @@ int QgsTINInterpolator::insertData( QgsFeature* f, bool zCoord, int attr, InputT

case QGis::WKBMultiPolygon25D:
hasZValue = true;
FALLTHROUGH;
case QGis::WKBMultiPolygon:
{
int nPolys;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -230,6 +230,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
case QGis::UnknownUnit:
myScaleBarUnitLabel = tr( " unknown" );
//intentional fall-through
FALLTHROUGH;
default:
QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( myMapUnits ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -438,6 +438,7 @@ void QgsLabelPropertyDialog::enableDataDefinedWidgets( QgsVectorLayer* vlayer )
break;
case QgsPalLayerSettings::Size:
mFontSizeSpinBox->setEnabled( true );
break;
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgis.h
Expand Up @@ -414,3 +414,9 @@ typedef unsigned long long qgssize;
#endif
#endif
#endif

#if defined(__clang__)
#define FALLTHROUGH [[clang::fallthrough]]
#else
#define FALLTHROUGH
#endif
1 change: 1 addition & 0 deletions src/core/qgsdistancearea.cpp
Expand Up @@ -1073,6 +1073,7 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,
case QGis::UnknownUnit:
unitLabel = QObject::tr( " unknown" );
//intentional fall-through
FALLTHROUGH;
default:
QgsDebugMsg( QString( "Error: not picked up map units - actual value = %1" ).arg( u ) );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsexpression.cpp
Expand Up @@ -3640,6 +3640,7 @@ QVariant QgsExpression::NodeBinaryOperator::eval( QgsExpression *parent, const Q
return QVariant( sL + sR );
}
//intentional fall-through
FALLTHROUGH;
case boMinus:
case boMul:
case boDiv:
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgslabel.cpp
Expand Up @@ -605,6 +605,7 @@ const unsigned char* QgsLabel::labelPoint( labelpoint& point, const unsigned cha
case QGis::WKBLineString25D:
dims = 3;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBLineString: // Line center
{
#ifndef QT_NO_DEBUG
Expand Down Expand Up @@ -656,6 +657,7 @@ const unsigned char* QgsLabel::labelPoint( labelpoint& point, const unsigned cha
case QGis::WKBPolygon25D:
dims = 3;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBPolygon: // centroid of outer ring
{
#ifndef QT_NO_DEBUG
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsogcutils.cpp
Expand Up @@ -1125,6 +1125,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry* geometry, QDomDocumen
case QGis::WKBMultiPoint25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBMultiPoint:
{
QDomElement multiPointElem = doc.createElement( "gml:MultiPoint" );
Expand Down Expand Up @@ -1158,6 +1159,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry* geometry, QDomDocumen
case QGis::WKBLineString25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBLineString:
{
QDomElement lineStringElem = doc.createElement( "gml:LineString" );
Expand Down Expand Up @@ -1192,6 +1194,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry* geometry, QDomDocumen
case QGis::WKBMultiLineString25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBMultiLineString:
{
QDomElement multiLineStringElem = doc.createElement( "gml:MultiLineString" );
Expand Down Expand Up @@ -1238,6 +1241,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry* geometry, QDomDocumen
case QGis::WKBPolygon25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBPolygon:
{
QDomElement polygonElem = doc.createElement( "gml:Polygon" );
Expand Down Expand Up @@ -1295,6 +1299,7 @@ QDomElement QgsOgcUtils::geometryToGML( const QgsGeometry* geometry, QDomDocumen
case QGis::WKBMultiPolygon25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBMultiPolygon:
{
QDomElement multiPolygonElem = doc.createElement( "gml:MultiPolygon" );
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgspointlocator.cpp
Expand Up @@ -332,6 +332,7 @@ static QgsPointLocator::MatchList _geometrySegmentsInRect( QgsGeometry* geom, co
case QGis::WKBLineString25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBLineString:
{
int nPoints;
Expand Down Expand Up @@ -365,6 +366,7 @@ static QgsPointLocator::MatchList _geometrySegmentsInRect( QgsGeometry* geom, co
case QGis::WKBMultiLineString25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBMultiLineString:
{
int nLines;
Expand Down Expand Up @@ -405,6 +407,7 @@ static QgsPointLocator::MatchList _geometrySegmentsInRect( QgsGeometry* geom, co
case QGis::WKBPolygon25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBPolygon:
{
int nRings;
Expand Down Expand Up @@ -445,6 +448,7 @@ static QgsPointLocator::MatchList _geometrySegmentsInRect( QgsGeometry* geom, co
case QGis::WKBMultiPolygon25D:
hasZValue = true;
//intentional fall-through
FALLTHROUGH;
case QGis::WKBMultiPolygon:
{
int nPolygons;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -400,6 +400,7 @@ void QgsGeorefPluginGui::generateGDALScript()
break;
}
}
FALLTHROUGH;
default:
mMessageBar->pushMessage( tr( "Invalid Transform" ), tr( "GDAL scripting is not supported for %1 transformation." )
.arg( convertTransformEnumToString( mTransformParam ) )
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/grass/qgsgrassnewmapset.cpp
Expand Up @@ -17,6 +17,7 @@
#include "qgsgrassnewmapset.h"
#include "qgsgrassplugin.h"
#include "qgsgrass.h"
#include "qgis.h"

#include "qgisinterface.h"
#include "qgsapplication.h"
Expand Down Expand Up @@ -298,6 +299,7 @@ int QgsGrassNewMapset::nextId() const
id = MAPSET;
break;
}
FALLTHROUGH;
case DATABASE:
case CRS:
case REGION:
Expand Down
6 changes: 6 additions & 0 deletions src/providers/mssql/qgsmssqlprovider.cpp
Expand Up @@ -1497,36 +1497,42 @@ void QgsMssqlProvider::mssqlWkbTypeAndDimension( QGis::WkbType wkbType, QString
{
case QGis::WKBPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPoint:
geometryType = "POINT";
break;

case QGis::WKBLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBLineString:
geometryType = "LINESTRING";
break;

case QGis::WKBPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPolygon:
geometryType = "POLYGON";
break;

case QGis::WKBMultiPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPoint:
geometryType = "MULTIPOINT";
break;

case QGis::WKBMultiLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiLineString:
geometryType = "MULTILINESTRING";
break;

case QGis::WKBMultiPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPolygon:
geometryType = "MULTIPOLYGON";
break;
Expand Down
7 changes: 7 additions & 0 deletions src/providers/postgres/qgspostgresconn.cpp
Expand Up @@ -1259,6 +1259,7 @@ qint64 QgsPostgresConn::getBinaryInt( QgsPostgresResult &queryResult, int row, i
default:
QgsDebugMsg( QString( "unexpected size %1" ).arg( s ) );
//intentional fall-through
FALLTHROUGH;
case 4:
oid = *( quint32 * )p;
if ( mSwapEndian )
Expand Down Expand Up @@ -1466,36 +1467,42 @@ void QgsPostgresConn::postgisWkbType( QGis::WkbType wkbType, QString &geometryTy
{
case QGis::WKBPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPoint:
geometryType = "POINT";
break;

case QGis::WKBLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBLineString:
geometryType = "LINESTRING";
break;

case QGis::WKBPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPolygon:
geometryType = "POLYGON";
break;

case QGis::WKBMultiPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPoint:
geometryType = "MULTIPOINT";
break;

case QGis::WKBMultiLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiLineString:
geometryType = "MULTILINESTRING";
break;

case QGis::WKBMultiPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPolygon:
geometryType = "MULTIPOLYGON";
break;
Expand Down
6 changes: 6 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -234,36 +234,42 @@ QgsSpatiaLiteProvider::createEmptyLayer(
{
case QGis::WKBPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPoint:
geometryType = "POINT";
break;

case QGis::WKBLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBLineString:
geometryType = "LINESTRING";
break;

case QGis::WKBPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBPolygon:
geometryType = "POLYGON";
break;

case QGis::WKBMultiPoint25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPoint:
geometryType = "MULTIPOINT";
break;

case QGis::WKBMultiLineString25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiLineString:
geometryType = "MULTILINESTRING";
break;

case QGis::WKBMultiPolygon25D:
dim = 3;
FALLTHROUGH;
case QGis::WKBMultiPolygon:
geometryType = "MULTIPOLYGON";
break;
Expand Down

0 comments on commit cf3c55b

Please sign in to comment.