Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade clang-tidy in CI build #2062

Merged
merged 8 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Checks: >
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-macro-to-enum,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-non-private-member-variables-in-classes,
Expand Down Expand Up @@ -55,6 +56,7 @@ Checks: >
-performance-avoid-endl,
-performance-enum-size,
readability-*,
-readability-avoid-nested-conditional-operator,
-readability-braces-around-statements,
-readability-const-return-type,
-readability-convert-member-functions-to-static,
Expand All @@ -66,6 +68,7 @@ Checks: >
-readability-magic-numbers,
-readability-make-member-function-const,
-readability-named-parameter,
-readability-redundant-casting,
-readability-redundant-declaration,
-readability-simplify-boolean-expr,
-readability-suspicious-call-argument,
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y clang-tidy-15 libboost-dev
sudo apt-get install -y clang-tidy-18 libboost-dev
- name: Check
run: |
cmake --preset linux-ci-build-with-clang-tidy
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@
"cacheVariables": {
"BOOST_ROOT": "/usr",
"CMAKE_UNITY_BUILD": "ON",
"QL_CLANG_TIDY": "clang-tidy-15",
"QL_CLANG_TIDY": "clang-tidy-18",
"QL_CLANG_TIDY_OPTIONS": "-quiet;-fix",
"QL_USE_CLANG_TIDY": "ON",
"QL_USE_STD_CLASSES": "ON"
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace QuantLib {
// specified in the settings (if any)
ext::optional<bool> includeToday =
Settings::instance().includeTodaysCashFlows();
if (includeToday) // NOLINT(readability-implicit-bool-conversion)
includeRefDate = *includeToday;
if (includeToday.has_value())
includeRefDate = includeToday;
}
return Event::hasOccurred(refDate, includeRefDate);
}
Expand Down
18 changes: 9 additions & 9 deletions ql/experimental/basismodels/swaptioncfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ namespace QuantLib {
std::vector<Real> floatWeights_;

public:
inline const Leg& floatLeg() const { return floatLeg_; }
inline const std::vector<Real>& floatTimes() const { return floatTimes_; }
inline const std::vector<Real>& floatWeights() const { return floatWeights_; }
const Leg& floatLeg() const { return floatLeg_; }
const std::vector<Real>& floatTimes() const { return floatTimes_; }
const std::vector<Real>& floatWeights() const { return floatWeights_; }
IborLegCashFlows(const Leg& iborLeg,
const Handle<YieldTermStructure>& discountCurve,
bool contTenorSpread = true);
Expand All @@ -65,10 +65,10 @@ namespace QuantLib {
SwapCashFlows() = default;
; // allow default constructor which does nothing
// inspectors
inline const Leg& fixedLeg() const { return fixedLeg_; }
inline const std::vector<Real>& fixedTimes() const { return fixedTimes_; }
inline const std::vector<Real>& fixedWeights() const { return fixedWeights_; }
inline const std::vector<Real>& annuityWeights() const { return annuityWeights_; }
const Leg& fixedLeg() const { return fixedLeg_; }
const std::vector<Real>& fixedTimes() const { return fixedTimes_; }
const std::vector<Real>& fixedWeights() const { return fixedWeights_; }
const std::vector<Real>& annuityWeights() const { return annuityWeights_; }
};


Expand All @@ -84,8 +84,8 @@ namespace QuantLib {
SwaptionCashFlows() = default;
; // allow default constructor which does nothing
// inspectors
inline ext::shared_ptr<Swaption> swaption() const { return swaption_; }
inline const std::vector<Real>& exerciseTimes() const { return exerciseTimes_; }
ext::shared_ptr<Swaption> swaption() const { return swaption_; }
const std::vector<Real>& exerciseTimes() const { return exerciseTimes_; }
};


Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/callablebonds/treecallablebondengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace QuantLib {
}

void TreeCallableFixedRateBondEngine::calculate() const {
return calculateWithSpread(arguments_.spread);
calculateWithSpread(arguments_.spread);
}

void TreeCallableFixedRateBondEngine::calculateWithSpread(Spread s) const {
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/math/fireflyalgorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace QuantLib {
std::vector<Array> *xI_;

virtual Real intensityImpl(Real valueX, Real valueY, Real distance) = 0;
inline Real distance(const Array& x, const Array& y) const {
Real distance(const Array& x, const Array& y) const {
Real d = 0.0;
for (Size i = 0; i < N_; i++) {
Real diff = x[i] - y[i];
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/math/hybridsimulatedannealing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Mathl. Comput. Modelling, 967-973, 1989
#include <ql/math/optimization/constraint.hpp>
#include <ql/math/optimization/levenbergmarquardt.hpp>
#include <ql/math/optimization/problem.hpp>
#include <ql/shared_ptr.hpp>
#include <utility>

namespace QuantLib {
Expand Down Expand Up @@ -95,8 +96,7 @@ namespace QuantLib {
reAnnealSteps_(reAnnealSteps == 0 ? QL_MAX_INTEGER : reAnnealSteps),
resetScheme_(resetScheme), resetSteps_(resetSteps == 0 ? QL_MAX_INTEGER : resetSteps),
localOptimizer_(localOptimizer),
optimizeScheme_(localOptimizer != nullptr ? optimizeScheme : NoLocalOptimize) {
}
optimizeScheme_(localOptimizer != nullptr ? optimizeScheme : NoLocalOptimize) {}

EndCriteria::Type minimize(Problem& P, const EndCriteria& endCriteria) override;

Expand Down
36 changes: 18 additions & 18 deletions ql/experimental/math/hybridsimulatedannealingfunctors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace QuantLib
explicit SamplerLogNormal(unsigned long seed = SeedGenerator::instance().get()) :
generator_(seed), distribution_(0.0, 1.0) {};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
for (Size i = 0; i < currentPoint.size(); i++)
Expand All @@ -67,7 +67,7 @@ namespace QuantLib
explicit SamplerGaussian(unsigned long seed = SeedGenerator::instance().get()) :
generator_(seed), distribution_(0.0, 1.0) {};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
for (Size i = 0; i < currentPoint.size(); i++)
Expand All @@ -92,7 +92,7 @@ namespace QuantLib
: generator_(seed), distribution_(0.0, 1.0),
lower_(std::move(lower)), upper_(std::move(upper)){};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
for (Size i = 0; i < currentPoint.size(); i++){
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace QuantLib
: generator_(seed), distribution_(0.0, 1.0),
lower_(std::move(lower)), upper_(std::move(upper)){};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
for (Size i = 0; i < currentPoint.size(); i++){
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace QuantLib
explicit SamplerCauchy(unsigned long seed = SeedGenerator::instance().get()) :
generator_(seed), distribution_(0.0, 1.0) {};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
for (Size i = 0; i < currentPoint.size(); i++)
Expand All @@ -183,7 +183,7 @@ namespace QuantLib
QL_REQUIRE(lower_.size() == upper_.size(), "Incompatible input");
};

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == lower_.size(), "Incompatible input");
QL_REQUIRE(newPoint.size() == temp.size(), "Incompatible input");
Expand All @@ -210,7 +210,7 @@ namespace QuantLib
optimizer will be able to escape a local optimum.
*/
struct ProbabilityAlwaysDownhill {
inline bool operator()(Real currentValue, Real newValue, const Array &temp) {
bool operator()(Real currentValue, Real newValue, const Array &temp) {
return currentValue > newValue; //return true if new value is lower than old value
}
};
Expand All @@ -224,7 +224,7 @@ namespace QuantLib
public:
explicit ProbabilityBoltzmann(unsigned long seed = SeedGenerator::instance().get()) : generator_(seed) {};

inline bool operator()(Real currentValue, Real newValue, const Array &temp) {
bool operator()(Real currentValue, Real newValue, const Array &temp) {
Real temperature = *std::max_element(temp.begin(), temp.end());
return (1.0 / (1.0 + exp((newValue - currentValue) / temperature))) > distribution_(generator_);
}
Expand All @@ -241,7 +241,7 @@ namespace QuantLib
public:
explicit ProbabilityBoltzmannDownhill(unsigned long seed = SeedGenerator::instance().get()) : generator_(seed) {};

inline bool operator()(Real currentValue, Real newValue, const Array &temp) {
bool operator()(Real currentValue, Real newValue, const Array &temp) {
if (newValue < currentValue)
return true;
Real mTemperature = *std::max_element(temp.begin(), temp.end());
Expand All @@ -258,7 +258,7 @@ namespace QuantLib
public:
TemperatureBoltzmann(Real initialTemp, Size dimension)
: initialTemp_(dimension, initialTemp) {}
inline void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
QL_REQUIRE(currTemp.size() == initialTemp_.size(), "Incompatible input");
QL_REQUIRE(currTemp.size() == newTemp.size(), "Incompatible input");
for (Size i = 0; i < initialTemp_.size(); i++)
Expand All @@ -274,7 +274,7 @@ namespace QuantLib
public:
TemperatureCauchy(Real initialTemp, Size dimension)
: initialTemp_(dimension, initialTemp) {}
inline void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
QL_REQUIRE(currTemp.size() == initialTemp_.size(), "Incompatible input");
QL_REQUIRE(currTemp.size() == newTemp.size(), "Incompatible input");
for (Size i = 0; i < initialTemp_.size(); i++)
Expand All @@ -289,7 +289,7 @@ namespace QuantLib
TemperatureCauchy1D(Real initialTemp, Size dimension) :
inverseN_(1.0 / dimension),
initialTemp_(dimension, initialTemp) {}
inline void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
QL_REQUIRE(currTemp.size() == initialTemp_.size(), "Incompatible input");
QL_REQUIRE(currTemp.size() == newTemp.size(), "Incompatible input");
for (Size i = 0; i < initialTemp_.size(); i++)
Expand All @@ -304,7 +304,7 @@ namespace QuantLib
public:
TemperatureExponential(Real initialTemp, Size dimension, Real power = 0.95)
: initialTemp_(dimension, initialTemp), power_(power) {}
inline void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
QL_REQUIRE(currTemp.size() == initialTemp_.size(), "Incompatible input");
QL_REQUIRE(currTemp.size() == newTemp.size(), "Incompatible input");
for (Size i = 0; i < initialTemp_.size(); i++)
Expand All @@ -326,7 +326,7 @@ namespace QuantLib
for (Size i = 0; i < initialTemp_.size(); i++)
exponent_[i] = -std::log(finalTemp_[i] / initialTemp_[i])*coeff;
}
inline void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
void operator()(Array &newTemp, const Array &currTemp, const Array &steps) {
QL_REQUIRE(currTemp.size() == initialTemp_.size(), "Incompatible input");
QL_REQUIRE(currTemp.size() == newTemp.size(), "Incompatible input");
for (Size i = 0; i < initialTemp_.size(); i++)
Expand All @@ -342,8 +342,8 @@ namespace QuantLib
struct ReannealingTrivial {
ReannealingTrivial() = default;
;
inline void setProblem(Problem &P) {};
inline void operator()(Array & steps, const Array &currentPoint,
void setProblem(Problem &P) {};
void operator()(Array & steps, const Array &currentPoint,
Real aCurrentValue, const Array & currTemp) {};
};
//! Reannealing Finite Difference
Expand Down Expand Up @@ -375,8 +375,8 @@ namespace QuantLib
}
}
}
inline void setProblem(Problem &P) { problem_ = &P; };
inline void operator()(Array & steps, const Array &currentPoint,
void setProblem(Problem &P) { problem_ = &P; };
void operator()(Array & steps, const Array &currentPoint,
Real currentValue, const Array & currTemp) {
QL_REQUIRE(currTemp.size() == N_, "Incompatible input");
QL_REQUIRE(steps.size() == N_, "Incompatible input");
Expand Down
8 changes: 4 additions & 4 deletions ql/experimental/math/isotropicrandomwalk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace QuantLib {
QL_REQUIRE(dim_ == weights_.size(), "Invalid weights");
}
template <class InputIterator>
inline void nextReal(InputIterator first) {
void nextReal(InputIterator first) {
Real radius = distribution_(engine_);
Array::const_iterator weight = weights_.begin();
if (dim_ > 1) {
Expand All @@ -76,11 +76,11 @@ namespace QuantLib {
*first = radius*(*weight);
}
}
inline void setDimension(Size dim) {
void setDimension(Size dim) {
dim_ = dim;
weights_ = Array(dim, 1.0);
}
inline void setDimension(Size dim, const Array& weights) {
void setDimension(Size dim, const Array& weights) {
QL_REQUIRE(dim == weights.size(), "Invalid weights");
dim_ = dim;
weights_ = weights;
Expand All @@ -90,7 +90,7 @@ namespace QuantLib {
but if the limits are provided, they are used to rescale the sphere so as to make it to an
ellipsoid, with different radius in different dimensions.
*/
inline void setDimension(Size dim,
void setDimension(Size dim,
const Array& lowerBound, const Array& upperBound) {
QL_REQUIRE(dim == lowerBound.size(),
"Incompatible dimension and lower bound");
Expand Down
Loading
Loading