Skip to content

Commit

Permalink
Fix a bunch of suggestions from clang-tidy
Browse files Browse the repository at this point in the history
And add a new CLANG_TIDY_EXE cmake option. If this is set to the
path to the clang_tidy executable then a bunch of clang-tidy
checks will be run during compilation.
  • Loading branch information
nyalldawson committed Feb 20, 2017
1 parent a0f655a commit 7daa4b5
Show file tree
Hide file tree
Showing 135 changed files with 364 additions and 544 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Expand Up @@ -671,6 +671,20 @@ INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})
# that may be in the same install prefix
LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src/core ${CMAKE_BINARY_DIR}/src/gui)

####################################################
# clang-tidy
FIND_PROGRAM(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
IF(NOT CLANG_TIDY_EXE)
MESSAGE(STATUS "clang-tidy not found.")
ELSE(NOT CLANG_TIDY_EXE)
MESSAGE(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
SET(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-clang-analyzer-alpha.*,-cppcoreguidelines*,-readability-implicit-bool-cast,-llvm-include-order,-cert-err58-cpp,-modernize-pass-by-value,-google-readability-braces-around-statements,-modernize-use-auto,-modernize-loop-convert,-readability-else-after-return,-readability-braces-around-statements,-google-runtime-references,-readability-named-parameter,-google-default-arguments,-google-readability-todo,-readability-inconsistent-declaration-parameter-name,-cert-flp30-c,-google-readability-casting,-clang-analyzer-security.FloatLoopCounter,-google-runtime-int,-modernize-use-using,-google-explicit-constructor,-google-build-using-namespace,-cert-err34-c,-clang-analyzer-core.CallAndMessage,-google-readability-function-size,-modernize-make-shared,-modernize-use-nullptr,-clang-analyzer-cplusplus.NewDeleteLeaks,-clang-analyzer-core.NonNullParamChecker,performance-unnecessary-copy-initialization,-readability-simplify-boolean-expr,-modernize-raw-string-literal,-performance-unnecessary-copy-initialization")
ENDIF(NOT CLANG_TIDY_EXE)

#############################################################
# create qgsversion.h
IF (EXISTS ${CMAKE_SOURCE_DIR}/.git/index)
Expand Down
16 changes: 16 additions & 0 deletions python/core/symbology-ng/qgsfillsymbollayer.sip
Expand Up @@ -487,6 +487,10 @@ class QgsImageFillSymbolLayer: QgsFillSymbolLayer
protected:

virtual void applyDataDefinedSettings( QgsSymbolRenderContext& context );

private:

QgsImageFillSymbolLayer( const QgsImageFillSymbolLayer& other );
};

/** \ingroup core
Expand Down Expand Up @@ -844,6 +848,10 @@ class QgsLinePatternFillSymbolLayer: QgsImageFillSymbolLayer

QSet<QString> usedAttributes( const QgsRenderContext& context ) const;

private:

QgsLinePatternFillSymbolLayer( const QgsLinePatternFillSymbolLayer& other );

};

class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer
Expand Down Expand Up @@ -945,6 +953,10 @@ class QgsPointPatternFillSymbolLayer : QgsImageFillSymbolLayer

protected:
void applyDataDefinedSettings( QgsSymbolRenderContext& context );

private:

QgsPointPatternFillSymbolLayer( const QgsPointPatternFillSymbolLayer& other );
};

class QgsCentroidFillSymbolLayer : QgsFillSymbolLayer
Expand Down Expand Up @@ -1001,4 +1013,8 @@ class QgsCentroidFillSymbolLayer : QgsFillSymbolLayer
/** Returns whether a point is drawn for all parts or only on the biggest part of multi-part features.
* @note added in 2.16 */
bool pointOnAllParts() const;

private:

QgsCentroidFillSymbolLayer( const QgsCentroidFillSymbolLayer& other );
};
4 changes: 4 additions & 0 deletions python/core/symbology-ng/qgslinesymbollayer.sip
Expand Up @@ -283,4 +283,8 @@ class QgsMarkerLineSymbolLayer : QgsLineSymbolLayer
void renderPolylineVertex( const QPolygonF& points, QgsSymbolRenderContext& context, Placement placement = Vertex );
void renderPolylineCentral( const QPolygonF& points, QgsSymbolRenderContext& context );
double markerAngle( const QPolygonF& points, bool isRing, int vertex );

private:

QgsMarkerLineSymbolLayer( const QgsMarkerLineSymbolLayer& other );
};
4 changes: 4 additions & 0 deletions python/core/symbology-ng/qgsvectorfieldsymbollayer.sip
Expand Up @@ -85,4 +85,8 @@ class QgsVectorFieldSymbolLayer : QgsMarkerSymbolLayer
const QgsMapUnitScale& distanceMapUnitScale() const;

QRectF bounds( QPointF point, QgsSymbolRenderContext& context );

private:

QgsVectorFieldSymbolLayer( const QgsVectorFieldSymbolLayer& other );
};
7 changes: 7 additions & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -217,6 +217,13 @@ ENDIF (NOT ANDROID)

TARGET_LINK_LIBRARIES(qgis_analysis qgis_core)

# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(
qgis_analysis PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
ENDIF(CLANG_TIDY_EXE)

# install

Expand Down
8 changes: 0 additions & 8 deletions src/analysis/interpolation/Point3D.cc
Expand Up @@ -17,14 +17,6 @@
#include "Point3D.h"
#include "qgslogger.h"

Point3D& Point3D::operator=( const Point3D & p )
{
mX = p.mX;
mY = p.mY;
mZ = p.mZ;
return ( *this );
}

bool Point3D::operator==( const Point3D& p ) const
{
return ( mX == p.getX() && mY == p.getY() && mZ == p.getZ() );
Expand Down
1 change: 0 additions & 1 deletion src/analysis/interpolation/Point3D.h
Expand Up @@ -36,7 +36,6 @@ class ANALYSIS_EXPORT Point3D
//! Constructor with the x-, y- and z-coordinate as arguments
Point3D( double x, double y, double z );
Point3D( const Point3D& p );
Point3D& operator=( const Point3D& p );
bool operator==( const Point3D& p ) const;
bool operator!=( const Point3D& p ) const;
//! Calculates the three-dimensional distance to another point
Expand Down
15 changes: 0 additions & 15 deletions src/analysis/interpolation/Vector3D.cc
Expand Up @@ -29,21 +29,6 @@ void Vector3D::standardise()
setZ( getZ() / length );
}

Vector3D::Vector3D( const Vector3D& v )
: mX( v.mX )
, mY( v.mY )
, mZ( v.mZ )
{
}

Vector3D& Vector3D::operator=( const Vector3D & v )
{
mX = v.mX;
mY = v.mY;
mZ = v.mZ;
return ( *this );
}

bool Vector3D::operator==( const Vector3D& v ) const
{
return ( mX == v.getX() && mY == v.getY() && mZ == v.getZ() );
Expand Down
3 changes: 0 additions & 3 deletions src/analysis/interpolation/Vector3D.h
Expand Up @@ -41,10 +41,7 @@ class ANALYSIS_EXPORT Vector3D
Vector3D( double x, double y, double z );
//! Default constructor
Vector3D();
//! Copy constructor
Vector3D( const Vector3D& v );

Vector3D& operator=( const Vector3D& v );
bool operator==( const Vector3D& v ) const;
bool operator!=( const Vector3D& v ) const;
//! Returns the x-component of the vector
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/interpolation/qgsinterpolator.cpp
Expand Up @@ -35,11 +35,6 @@ QgsInterpolator::QgsInterpolator()

}

QgsInterpolator::~QgsInterpolator()
{

}

int QgsInterpolator::cacheBaseData()
{
if ( mLayerData.size() < 1 )
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/interpolation/qgsinterpolator.h
Expand Up @@ -57,7 +57,7 @@ class ANALYSIS_EXPORT QgsInterpolator

QgsInterpolator( const QList<LayerData>& layerData );

virtual ~QgsInterpolator();
virtual ~QgsInterpolator() = default;

/** Calculates interpolation value for map coordinates x, y
@param x x-coordinate (in map units)
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/network/qgsvectorlayerdirector.cpp
Expand Up @@ -118,11 +118,6 @@ QgsVectorLayerDirector::QgsVectorLayerDirector( QgsVectorLayer *myLayer,
mBothDirectionValue = bothDirectionValue;
}

QgsVectorLayerDirector::~QgsVectorLayerDirector()
{

}

QString QgsVectorLayerDirector::name() const
{
return QStringLiteral( "Vector line" );
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/network/qgsvectorlayerdirector.h
Expand Up @@ -65,7 +65,7 @@ class ANALYSIS_EXPORT QgsVectorLayerDirector : public QgsGraphDirector
const Direction defaultDirection
);

virtual ~QgsVectorLayerDirector();
virtual ~QgsVectorLayerDirector() = default;

/*
* MANDATORY DIRECTOR PROPERTY DECLARATION
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/raster/qgsderivativefilter.cpp
Expand Up @@ -23,11 +23,6 @@ QgsDerivativeFilter::QgsDerivativeFilter( const QString& inputFile, const QStrin

}

QgsDerivativeFilter::~QgsDerivativeFilter()
{

}

float QgsDerivativeFilter::calcFirstDerX( float* x11, float* x21, float* x31, float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
{
//the basic formula would be simple, but we need to test for nodata values...
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsderivativefilter.h
Expand Up @@ -27,7 +27,7 @@ class ANALYSIS_EXPORT QgsDerivativeFilter : public QgsNineCellFilter
{
public:
QgsDerivativeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
virtual ~QgsDerivativeFilter();
virtual ~QgsDerivativeFilter() = default;
//to be implemented by subclasses
virtual float processNineCellWindow( float* x11, float* x21, float* x31,
float* x12, float* x22, float* x32,
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -43,11 +43,6 @@ QgsNineCellFilter::QgsNineCellFilter()
{
}

QgsNineCellFilter::~QgsNineCellFilter()
{

}

int QgsNineCellFilter::processRaster( QProgressDialog* p )
{
GDALAllRegister();
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsninecellfilter.h
Expand Up @@ -34,7 +34,7 @@ class ANALYSIS_EXPORT QgsNineCellFilter
public:
//! Constructor that takes input file, output file and output format (GDAL string)
QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
virtual ~QgsNineCellFilter();
virtual ~QgsNineCellFilter() = default;

/** Starts the calculation, reads from mInputFile and stores the result in mOutputFile
@param p progress dialog that receives update and that is checked for abort. 0 if no progress bar is needed.
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsrastermatrix.cpp
Expand Up @@ -16,7 +16,7 @@
***************************************************************************/

#include "qgsrastermatrix.h"
#include <string.h>
#include <cstring>
#include <qmath.h>

QgsRasterMatrix::QgsRasterMatrix()
Expand Down
6 changes: 0 additions & 6 deletions src/analysis/raster/qgsruggednessfilter.cpp
Expand Up @@ -27,12 +27,6 @@ QgsRuggednessFilter::QgsRuggednessFilter(): QgsNineCellFilter( QLatin1String( ""

}


QgsRuggednessFilter::~QgsRuggednessFilter()
{

}

float QgsRuggednessFilter::processNineCellWindow( float* x11, float* x21, float* x31,
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsruggednessfilter.h
Expand Up @@ -28,7 +28,7 @@ class ANALYSIS_EXPORT QgsRuggednessFilter: public QgsNineCellFilter
{
public:
QgsRuggednessFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
~QgsRuggednessFilter();
~QgsRuggednessFilter() = default;

protected:

Expand Down
5 changes: 0 additions & 5 deletions src/analysis/raster/qgsslopefilter.cpp
Expand Up @@ -23,11 +23,6 @@ QgsSlopeFilter::QgsSlopeFilter( const QString& inputFile, const QString& outputF

}

QgsSlopeFilter::~QgsSlopeFilter()
{

}

float QgsSlopeFilter::processNineCellWindow( float* x11, float* x21, float* x31,
float* x12, float* x22, float* x32, float* x13, float* x23, float* x33 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgsslopefilter.h
Expand Up @@ -27,7 +27,7 @@ class ANALYSIS_EXPORT QgsSlopeFilter: public QgsDerivativeFilter
{
public:
QgsSlopeFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
~QgsSlopeFilter();
~QgsSlopeFilter() = default;

/** Calculates output value from nine input values. The input values and the output value can be equal to the
nodata value if not present or outside of the border. Must be implemented by subclasses*/
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/raster/qgstotalcurvaturefilter.cpp
Expand Up @@ -23,11 +23,6 @@ QgsTotalCurvatureFilter::QgsTotalCurvatureFilter( const QString& inputFile, cons

}

QgsTotalCurvatureFilter::~QgsTotalCurvatureFilter()
{

}

float QgsTotalCurvatureFilter::processNineCellWindow( float* x11, float* x21, float* x31, float* x12,
float* x22, float* x32, float* x13, float* x23, float* x33 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/raster/qgstotalcurvaturefilter.h
Expand Up @@ -27,7 +27,7 @@ class ANALYSIS_EXPORT QgsTotalCurvatureFilter: public QgsNineCellFilter
{
public:
QgsTotalCurvatureFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat );
~QgsTotalCurvatureFilter();
~QgsTotalCurvatureFilter() = default;

protected:

Expand Down
8 changes: 4 additions & 4 deletions src/analysis/vector/mersenne-twister.cpp
Expand Up @@ -20,7 +20,7 @@
* 2015-02-17
*/

#include <stdio.h>
#include <cstdio>
#include "mersenne-twister.h"

/*
Expand All @@ -35,9 +35,9 @@ static const unsigned DIFF = SIZE - PERIOD;
static uint32_t MT[SIZE];
static unsigned index = 0;

#define M32(x) (0x80000000 & x) // 32nd Most Significant Bit
#define L31(x) (0x7FFFFFFF & x) // 31 Least Significant Bits
#define ODD(x) (x & 1) // Check if number is odd
#define M32(x) (0x80000000 & (x)) // 32nd Most Significant Bit
#define L31(x) (0x7FFFFFFF & (x)) // 31 Least Significant Bits
#define ODD(x) ((x) & 1) // Check if number is odd

#define UNROLL(expr) \
y = M32(MT[i]) | L31(MT[i+1]); \
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/vector/qgstransectsample.cpp
Expand Up @@ -22,7 +22,7 @@
#include <QProgressDialog>
#include <QFileInfo>
#ifndef _MSC_VER
#include <stdint.h>
#include <cstdint>
#endif
#include "mersenne-twister.h"
#include <limits>
Expand Down
8 changes: 8 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -1060,6 +1060,14 @@ IF (Qt5Positioning_FOUND)
)
ENDIF (Qt5Positioning_FOUND)

# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(
qgis_core PROPERTIES
CXX_CLANG_TIDY "${DO_CLANG_TIDY}"
)
ENDIF(CLANG_TIDY_EXE)

# install

INSTALL(TARGETS qgis_core
Expand Down
3 changes: 0 additions & 3 deletions src/core/annotations/qgshtmlannotation.cpp
Expand Up @@ -47,9 +47,6 @@ QgsHtmlAnnotation::QgsHtmlAnnotation( QObject* parent )
connect( mWebPage->mainFrame(), &QWebFrame::javaScriptWindowObjectCleared, this, &QgsHtmlAnnotation::javascript );
}

QgsHtmlAnnotation::~QgsHtmlAnnotation()
{}

void QgsHtmlAnnotation::setSourceFile( const QString& htmlFile )
{
QFile file( htmlFile );
Expand Down
2 changes: 1 addition & 1 deletion src/core/annotations/qgshtmlannotation.h
Expand Up @@ -42,7 +42,7 @@ class CORE_EXPORT QgsHtmlAnnotation: public QgsAnnotation
*/
QgsHtmlAnnotation( QObject* parent = nullptr );

~QgsHtmlAnnotation();
~QgsHtmlAnnotation() = default;

QSizeF minimumFrameSize() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/core/auth/qgsauthmethodregistry.cpp
Expand Up @@ -338,7 +338,7 @@ QFunctionPointer QgsAuthMethodRegistry::function( QString const & authMethodKey,
else
{
QgsDebugMsg( "Cannot load library: " + myLib.errorString() );
return 0;
return nullptr;
}
}

Expand Down

0 comments on commit 7daa4b5

Please sign in to comment.