From 07cc23fd471fe120ca80da7c7a9f04ea211ab550 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 10:07:29 +0200 Subject: [PATCH 1/7] Upgrade clang-tidy in CI build --- .github/workflows/tidy.yml | 4 ++-- CMakePresets.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml index d14c3a246cd..3ae610465ab 100644 --- a/.github/workflows/tidy.yml +++ b/.github/workflows/tidy.yml @@ -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 diff --git a/CMakePresets.json b/CMakePresets.json index e13a6905413..0c3276731bf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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" From 3a2c86d08e5348c6377e2f7f0f42b108b0976222 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 10:56:30 +0200 Subject: [PATCH 2/7] Don't remove casts needed for AAD support --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index d02eada6de4..cbfdac63061 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -66,6 +66,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, From e3fb82afe5f64590dae1d3ed5af848493eaf7dfd Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 10:59:07 +0200 Subject: [PATCH 3/7] Prevent botched fix from clang-tidy --- ql/patterns/observable.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ql/patterns/observable.hpp b/ql/patterns/observable.hpp index f7536c76964..0d366f4cd25 100644 --- a/ql/patterns/observable.hpp +++ b/ql/patterns/observable.hpp @@ -64,7 +64,7 @@ namespace QuantLib { friend class ObservableSettings; public: // constructors, assignment, destructor - Observable(); + Observable() = default; Observable(const Observable&); Observable& operator=(const Observable&); // delete the move operations because the semantics are not yet clear @@ -158,8 +158,6 @@ namespace QuantLib { // inline definitions - inline Observable::Observable() = default; - inline void ObservableSettings::registerDeferredObservers(const Observable::set_type& observers) { if (updatesDeferred()) { deferredObservers_.insert(observers.begin(), observers.end()); From c627b3c8a6d0917aeed87cab2bc78327424cac27 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 12:21:55 +0200 Subject: [PATCH 4/7] Keep macro to allow #if checks --- ql/version.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/ql/version.hpp b/ql/version.hpp index 68e741f066c..734c3202313 100644 --- a/ql/version.hpp +++ b/ql/version.hpp @@ -34,6 +34,7 @@ #define QL_VERSION "1.36-dev" //! version hexadecimal number +// NOLINTNEXTLINE(cppcoreguidelines-macro-to-enum) #define QL_HEX_VERSION 0x01360000 /*! @} */ From af365f0a188e924d18ee62021bc1978d7ad22015 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 11:07:28 +0000 Subject: [PATCH 5/7] Automated fixes by clang-tidy --- ql/experimental/basismodels/swaptioncfs.hpp | 18 +++++----- ql/experimental/math/fireflyalgorithm.hpp | 2 +- .../math/hybridsimulatedannealing.hpp | 3 +- .../math/hybridsimulatedannealingfunctors.hpp | 36 +++++++++---------- ql/experimental/math/isotropicrandomwalk.hpp | 8 ++--- .../math/particleswarmoptimization.hpp | 24 ++++++------- .../variancegamma/variancegammamodel.cpp | 5 +-- ql/instruments/bond.cpp | 7 ++-- ql/math/integrals/trapezoidintegral.hpp | 8 ++--- ql/math/interpolations/cubicinterpolation.hpp | 2 +- .../interpolations/lagrangeinterpolation.hpp | 2 +- ql/math/linearleastsquaresregression.hpp | 2 +- ql/math/sampledcurve.hpp | 4 +-- ql/methods/montecarlo/lsmbasissystem.cpp | 4 +-- ql/models/equity/batesmodel.cpp | 5 +-- ql/models/equity/gjrgarchmodel.cpp | 5 +-- ql/models/equity/hestonmodel.cpp | 5 +-- .../forward/mcvarianceswapengine.hpp | 2 +- .../vanilla/mceuropeanengine.hpp | 2 +- .../inflation/inflationhelpers.cpp | 9 ++--- ql/timeseries.hpp | 4 +-- ql/utilities/steppingiterator.hpp | 4 +-- test-suite/digitaloption.cpp | 9 ++--- test-suite/doublebinaryoption.cpp | 5 +-- 24 files changed, 92 insertions(+), 83 deletions(-) diff --git a/ql/experimental/basismodels/swaptioncfs.hpp b/ql/experimental/basismodels/swaptioncfs.hpp index 77a76101098..f13232a68ed 100644 --- a/ql/experimental/basismodels/swaptioncfs.hpp +++ b/ql/experimental/basismodels/swaptioncfs.hpp @@ -39,9 +39,9 @@ namespace QuantLib { std::vector floatWeights_; public: - inline const Leg& floatLeg() const { return floatLeg_; } - inline const std::vector& floatTimes() const { return floatTimes_; } - inline const std::vector& floatWeights() const { return floatWeights_; } + const Leg& floatLeg() const { return floatLeg_; } + const std::vector& floatTimes() const { return floatTimes_; } + const std::vector& floatWeights() const { return floatWeights_; } IborLegCashFlows(const Leg& iborLeg, const Handle& discountCurve, bool contTenorSpread = true); @@ -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& fixedTimes() const { return fixedTimes_; } - inline const std::vector& fixedWeights() const { return fixedWeights_; } - inline const std::vector& annuityWeights() const { return annuityWeights_; } + const Leg& fixedLeg() const { return fixedLeg_; } + const std::vector& fixedTimes() const { return fixedTimes_; } + const std::vector& fixedWeights() const { return fixedWeights_; } + const std::vector& annuityWeights() const { return annuityWeights_; } }; @@ -84,8 +84,8 @@ namespace QuantLib { SwaptionCashFlows() = default; ; // allow default constructor which does nothing // inspectors - inline ext::shared_ptr swaption() const { return swaption_; } - inline const std::vector& exerciseTimes() const { return exerciseTimes_; } + ext::shared_ptr swaption() const { return swaption_; } + const std::vector& exerciseTimes() const { return exerciseTimes_; } }; diff --git a/ql/experimental/math/fireflyalgorithm.hpp b/ql/experimental/math/fireflyalgorithm.hpp index 22f23fdc6c6..58fdf124078 100644 --- a/ql/experimental/math/fireflyalgorithm.hpp +++ b/ql/experimental/math/fireflyalgorithm.hpp @@ -120,7 +120,7 @@ namespace QuantLib { std::vector *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]; diff --git a/ql/experimental/math/hybridsimulatedannealing.hpp b/ql/experimental/math/hybridsimulatedannealing.hpp index d6a6b989603..d8575893b92 100644 --- a/ql/experimental/math/hybridsimulatedannealing.hpp +++ b/ql/experimental/math/hybridsimulatedannealing.hpp @@ -30,6 +30,7 @@ Mathl. Comput. Modelling, 967-973, 1989 #include #include #include +#include #include namespace QuantLib { @@ -97,7 +98,7 @@ namespace QuantLib { localOptimizer_(localOptimizer), optimizeScheme_(localOptimizer != nullptr ? optimizeScheme : NoLocalOptimize) { if (!localOptimizer) - localOptimizer.reset(new LevenbergMarquardt); + localOptimizer = ext::make_shared(); } EndCriteria::Type minimize(Problem& P, const EndCriteria& endCriteria) override; diff --git a/ql/experimental/math/hybridsimulatedannealingfunctors.hpp b/ql/experimental/math/hybridsimulatedannealingfunctors.hpp index 805892e1b6d..fa2938a7159 100644 --- a/ql/experimental/math/hybridsimulatedannealingfunctors.hpp +++ b/ql/experimental/math/hybridsimulatedannealingfunctors.hpp @@ -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 ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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++) @@ -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 ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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++) @@ -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 ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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++){ @@ -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 ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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++){ @@ -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 ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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++) @@ -183,7 +183,7 @@ namespace QuantLib QL_REQUIRE(lower_.size() == upper_.size(), "Incompatible input"); }; - inline void operator()(Array &newPoint, const Array ¤tPoint, const Array &temp) { + void operator()(Array &newPoint, const Array ¤tPoint, 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"); @@ -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 } }; @@ -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_); } @@ -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()); @@ -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++) @@ -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++) @@ -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++) @@ -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++) @@ -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++) @@ -342,8 +342,8 @@ namespace QuantLib struct ReannealingTrivial { ReannealingTrivial() = default; ; - inline void setProblem(Problem &P) {}; - inline void operator()(Array & steps, const Array ¤tPoint, + void setProblem(Problem &P) {}; + void operator()(Array & steps, const Array ¤tPoint, Real aCurrentValue, const Array & currTemp) {}; }; //! Reannealing Finite Difference @@ -375,8 +375,8 @@ namespace QuantLib } } } - inline void setProblem(Problem &P) { problem_ = &P; }; - inline void operator()(Array & steps, const Array ¤tPoint, + void setProblem(Problem &P) { problem_ = &P; }; + void operator()(Array & steps, const Array ¤tPoint, Real currentValue, const Array & currTemp) { QL_REQUIRE(currTemp.size() == N_, "Incompatible input"); QL_REQUIRE(steps.size() == N_, "Incompatible input"); diff --git a/ql/experimental/math/isotropicrandomwalk.hpp b/ql/experimental/math/isotropicrandomwalk.hpp index 72d6fdcdb56..5883aa879ff 100644 --- a/ql/experimental/math/isotropicrandomwalk.hpp +++ b/ql/experimental/math/isotropicrandomwalk.hpp @@ -55,7 +55,7 @@ namespace QuantLib { QL_REQUIRE(dim_ == weights_.size(), "Invalid weights"); } template - inline void nextReal(InputIterator first) { + void nextReal(InputIterator first) { Real radius = distribution_(engine_); Array::const_iterator weight = weights_.begin(); if (dim_ > 1) { @@ -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; @@ -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"); diff --git a/ql/experimental/math/particleswarmoptimization.hpp b/ql/experimental/math/particleswarmoptimization.hpp index 6a9add5eeb5..17d3783e183 100644 --- a/ql/experimental/math/particleswarmoptimization.hpp +++ b/ql/experimental/math/particleswarmoptimization.hpp @@ -156,11 +156,11 @@ namespace QuantLib { */ class TrivialInertia : public ParticleSwarmOptimization::Inertia { public: - inline void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { + void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { c0_ = c0; M_ = M; } - inline void setValues() override { + void setValues() override { for (Size i = 0; i < M_; i++) { (*V_)[i] *= c0_; } @@ -181,11 +181,11 @@ namespace QuantLib { : threshold_(threshold), rng_(seed) { QL_REQUIRE(threshold_ >= 0.0 && threshold_ < 1.0, "Threshold must be a Real in [0, 1)"); } - inline void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { + void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { M_ = M; c0_ = c0; } - inline void setValues() override { + void setValues() override { for (Size i = 0; i < M_; i++) { Real val = c0_*(threshold_ + (1.0 - threshold_)*rng_.nextReal()); (*V_)[i] *= val; @@ -208,13 +208,13 @@ namespace QuantLib { : threshold_(threshold) { QL_REQUIRE(threshold_ >= 0.0 && threshold_ < 1.0, "Threshold must be a Real in [0, 1)"); } - inline void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { + void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { N_ = N; c0_ = c0; iteration_ = 0; maxIterations_ = endCriteria.maxIterations(); } - inline void setValues() override { + void setValues() override { Real c0 = c0_*(threshold_ + (1.0 - threshold_)*(maxIterations_ - iteration_) / maxIterations_); for (Size i = 0; i < M_; i++) { (*V_)[i] *= c0; @@ -235,7 +235,7 @@ namespace QuantLib { AdaptiveInertia(Real minInertia, Real maxInertia, Size sh = 5, Size sl = 2) :minInertia_(minInertia), maxInertia_(maxInertia), sh_(sh), sl_(sl) {}; - inline void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { + void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { M_ = M; c0_ = c0; adaptiveCounter = 0; @@ -266,13 +266,13 @@ namespace QuantLib { :rng_(seed), generator_(seed), flight_(generator_, LevyFlightDistribution(1.0, alpha), 1, Array(1, 1.0), seed), threshold_(threshold) {}; - inline void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { + void setSize(Size M, Size N, Real c0, const EndCriteria& endCriteria) override { M_ = M; N_ = N; c0_ = c0; adaptiveCounter_ = std::vector(M_, 0); } - inline void setValues() override { + void setValues() override { for (Size i = 0; i < M_; i++) { if ((*pBF_)[i] < personalBestF_[i]) { personalBestF_[i] = (*pBF_)[i]; @@ -345,8 +345,8 @@ namespace QuantLib { */ class GlobalTopology : public ParticleSwarmOptimization::Topology { public: - inline void setSize(Size M) override { M_ = M; } - inline void findSocialBest() override { + void setSize(Size M) override { M_ = M; } + void findSocialBest() override { Real bestF = (*pBF_)[0]; Size bestP = 0; for (Size i = 1; i < M_; i++) { @@ -378,7 +378,7 @@ namespace QuantLib { KNeighbors(Size K = 1) :K_(K) { QL_REQUIRE(K > 0, "Neighbors need to be larger than 0"); } - inline void setSize(Size M) override { + void setSize(Size M) override { M_ = M; QL_ENSURE(K_ < M, "Number of neighbors need to be smaller than total particles in swarm"); } diff --git a/ql/experimental/variancegamma/variancegammamodel.cpp b/ql/experimental/variancegamma/variancegammamodel.cpp index 1e9201788d3..95358efa451 100644 --- a/ql/experimental/variancegamma/variancegammamodel.cpp +++ b/ql/experimental/variancegamma/variancegammamodel.cpp @@ -19,6 +19,7 @@ FOR A PARTICULAR PURPOSE. See the license for more details. #include #include +#include namespace QuantLib { @@ -40,10 +41,10 @@ namespace QuantLib { } void VarianceGammaModel::generateArguments() { - process_.reset(new VarianceGammaProcess(process_->s0(), + process_ = ext::make_shared(process_->s0(), process_->dividendYield(), process_->riskFreeRate(), - sigma(), nu(), theta())); + sigma(), nu(), theta()); } } diff --git a/ql/instruments/bond.cpp b/ql/instruments/bond.cpp index a565f3775b2..1b3c505c3e8 100644 --- a/ql/instruments/bond.cpp +++ b/ql/instruments/bond.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include namespace QuantLib { @@ -326,10 +327,10 @@ namespace QuantLib { Real amount = (R/100.0)*(notionals_[i-1]-notionals_[i]); ext::shared_ptr payment; if (i < notionalSchedule_.size()-1) - payment.reset(new AmortizingPayment(amount, - notionalSchedule_[i])); + payment = ext::make_shared(amount, + notionalSchedule_[i]); else - payment.reset(new Redemption(amount, notionalSchedule_[i])); + payment = ext::make_shared(amount, notionalSchedule_[i]); cashflows_.push_back(payment); redemptions_.push_back(payment); } diff --git a/ql/math/integrals/trapezoidintegral.hpp b/ql/math/integrals/trapezoidintegral.hpp index d8fbdb1dba7..ee2e4a1e503 100644 --- a/ql/math/integrals/trapezoidintegral.hpp +++ b/ql/math/integrals/trapezoidintegral.hpp @@ -82,7 +82,7 @@ namespace QuantLib { // Integration policies struct Default { - inline static Real integrate(const std::function& f, + static Real integrate(const std::function& f, Real a, Real b, Real I, @@ -95,11 +95,11 @@ namespace QuantLib { sum += f(x); return (I + dx*sum)/2.0; } - inline static Size nbEvalutions(){ return 2;} + static Size nbEvalutions(){ return 2;} }; struct MidPoint { - inline static Real integrate(const std::function& f, + static Real integrate(const std::function& f, Real a, Real b, Real I, @@ -113,7 +113,7 @@ namespace QuantLib { sum += f(x) + f(x+D); return (I + dx*sum)/3.0; } - inline static Size nbEvalutions(){ return 3;} + static Size nbEvalutions(){ return 3;} }; } diff --git a/ql/math/interpolations/cubicinterpolation.hpp b/ql/math/interpolations/cubicinterpolation.hpp index 0bb40efbfd4..d4e01b95ed0 100644 --- a/ql/math/interpolations/cubicinterpolation.hpp +++ b/ql/math/interpolations/cubicinterpolation.hpp @@ -787,7 +787,7 @@ namespace QuantLib { mutable std::vector dx_, S_; mutable TridiagonalOperator L_; - inline Real cubicInterpolatingPolynomialDerivative( + Real cubicInterpolatingPolynomialDerivative( Real a, Real b, Real c, Real d, Real u, Real v, Real w, Real z, Real x) const { return (-((((a-c)*(b-c)*(c-x)*z-(a-d)*(b-d)*(d-x)*w)*(a-x+b-x) diff --git a/ql/math/interpolations/lagrangeinterpolation.hpp b/ql/math/interpolations/lagrangeinterpolation.hpp index bc963898852..b31aa07ff53 100644 --- a/ql/math/interpolations/lagrangeinterpolation.hpp +++ b/ql/math/interpolations/lagrangeinterpolation.hpp @@ -112,7 +112,7 @@ namespace QuantLib { private: template - inline Real _value(const Iterator& yBegin, Real x) const { + Real _value(const Iterator& yBegin, Real x) const { const Real eps = 10*QL_EPSILON*std::abs(x); const auto iter = std::lower_bound( diff --git a/ql/math/linearleastsquaresregression.hpp b/ql/math/linearleastsquaresregression.hpp index ed9d83aadb2..821ffc244f1 100644 --- a/ql/math/linearleastsquaresregression.hpp +++ b/ql/math/linearleastsquaresregression.hpp @@ -40,7 +40,7 @@ namespace QuantLib { public: explicit LinearFct(Size i) : i_(i) {} - inline Real operator()(const Container& x) const { + Real operator()(const Container& x) const { return x[i_]; } diff --git a/ql/math/sampledcurve.hpp b/ql/math/sampledcurve.hpp index fc756104596..0b747466c76 100644 --- a/ql/math/sampledcurve.hpp +++ b/ql/math/sampledcurve.hpp @@ -138,14 +138,14 @@ namespace QuantLib { QL_DEPRECATED_DISABLE_WARNING template - inline const SampledCurve& transform(T x) { + const SampledCurve& transform(T x) { std::transform(values_.begin(), values_.end(), values_.begin(), x); return *this; } template - inline const SampledCurve& transformGrid(T x) { + const SampledCurve& transformGrid(T x) { std::transform(grid_.begin(), grid_.end(), grid_.begin(), x); return *this; diff --git a/ql/methods/montecarlo/lsmbasissystem.cpp b/ql/methods/montecarlo/lsmbasissystem.cpp index 398a281b71a..fb2e0c0866a 100644 --- a/ql/methods/montecarlo/lsmbasissystem.cpp +++ b/ql/methods/montecarlo/lsmbasissystem.cpp @@ -41,7 +41,7 @@ namespace QuantLib { class MonomialFct { public: explicit MonomialFct(Size order): order_(order) {} - inline Real operator()(const Real x) const { + Real operator()(const Real x) const { Real ret = 1.0; for(Size i=0; i +#include namespace QuantLib { @@ -36,11 +37,11 @@ namespace QuantLib { } void BatesModel::generateArguments() { - process_.reset(new BatesProcess( + process_ = ext::make_shared( process_->riskFreeRate(), process_->dividendYield(), process_->s0(), v0(), kappa(), theta(), sigma(), rho(), - lambda(), nu(), delta())); + lambda(), nu(), delta()); } BatesDetJumpModel::BatesDetJumpModel( diff --git a/ql/models/equity/gjrgarchmodel.cpp b/ql/models/equity/gjrgarchmodel.cpp index 5abf9c1ef8d..4d8a33b0d5d 100644 --- a/ql/models/equity/gjrgarchmodel.cpp +++ b/ql/models/equity/gjrgarchmodel.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace QuantLib { @@ -65,13 +66,13 @@ namespace QuantLib { } void GJRGARCHModel::generateArguments() { - process_.reset(new GJRGARCHProcess(process_->riskFreeRate(), + process_ = ext::make_shared(process_->riskFreeRate(), process_->dividendYield(), process_->s0(), v0(), omega(), alpha(), beta(), gamma(), lambda(), - process_->daysPerYear())); + process_->daysPerYear()); } } diff --git a/ql/models/equity/hestonmodel.cpp b/ql/models/equity/hestonmodel.cpp index b7330d168f5..d7f6f423220 100644 --- a/ql/models/equity/hestonmodel.cpp +++ b/ql/models/equity/hestonmodel.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace QuantLib { @@ -42,11 +43,11 @@ namespace QuantLib { } void HestonModel::generateArguments() { - process_.reset(new HestonProcess(process_->riskFreeRate(), + process_ = ext::make_shared(process_->riskFreeRate(), process_->dividendYield(), process_->s0(), v0(), kappa(), theta(), - sigma(), rho())); + sigma(), rho()); } } diff --git a/ql/pricingengines/forward/mcvarianceswapengine.hpp b/ql/pricingengines/forward/mcvarianceswapengine.hpp index 6d2f917e195..33dc5af06aa 100644 --- a/ql/pricingengines/forward/mcvarianceswapengine.hpp +++ b/ql/pricingengines/forward/mcvarianceswapengine.hpp @@ -329,7 +329,7 @@ namespace QuantLib { inline Real VariancePathPricer::operator()(const Path& path) const { - QL_REQUIRE(path.length() > 0, "the path cannot be empty"); + QL_REQUIRE(!path.empty(), "the path cannot be empty"); Time t0 = path.timeGrid().front(); Time t = path.timeGrid().back(); Time dt = path.timeGrid().dt(0); diff --git a/ql/pricingengines/vanilla/mceuropeanengine.hpp b/ql/pricingengines/vanilla/mceuropeanengine.hpp index f1ea2cfc6e1..3d774801c51 100644 --- a/ql/pricingengines/vanilla/mceuropeanengine.hpp +++ b/ql/pricingengines/vanilla/mceuropeanengine.hpp @@ -252,7 +252,7 @@ namespace QuantLib { } inline Real EuropeanPathPricer::operator()(const Path& path) const { - QL_REQUIRE(path.length() > 0, "the path cannot be empty"); + QL_REQUIRE(!path.empty(), "the path cannot be empty"); return payoff_(path.back()) * discount_; } diff --git a/ql/termstructures/inflation/inflationhelpers.cpp b/ql/termstructures/inflation/inflationhelpers.cpp index cce9c42cb1b..7ea04500768 100644 --- a/ql/termstructures/inflation/inflationhelpers.cpp +++ b/ql/termstructures/inflation/inflationhelpers.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -97,10 +98,10 @@ namespace QuantLib { Real nominal = 1000000.0; // has to be something but doesn't matter what Date start = nominalTermStructure_->referenceDate(); - zciis_.reset(new ZeroCouponInflationSwap(Swap::Payer, nominal, start, + zciis_ = ext::make_shared(Swap::Payer, nominal, start, maturity_, calendar_, paymentConvention_, dayCounter_, K, // fixed side & fixed rate - new_zii, swapObsLag_, observationInterpolation_)); + new_zii, swapObsLag_, observationInterpolation_); // Because very simple instrument only takes // standard discounting swap engine. zciis_->setPricingEngine( @@ -191,11 +192,11 @@ namespace QuantLib { Rate fixedRate = quote()->value(); Real nominal = 1000000.0; // has to be something but doesn't matter what - yyiis_.reset(new YearOnYearInflationSwap( + yyiis_ = ext::make_shared( Swap::Payer, nominal, fixedSchedule, fixedRate, dayCounter_, yoySchedule, new_yii, swapObsLag_, spread, dayCounter_, calendar_, // inflation index does not have a calendar - paymentConvention_)); + paymentConvention_); // The instrument takes a standard discounting swap engine. // The inflation-related work is done by the coupons. diff --git a/ql/timeseries.hpp b/ql/timeseries.hpp index b5e1f7d896b..9e9eef98e8f 100644 --- a/ql/timeseries.hpp +++ b/ql/timeseries.hpp @@ -145,8 +145,8 @@ namespace QuantLib { // The following typedef enables reverse iterators for // bidirectional_iterator_tag category. typedef std::conditional_t< - std::is_same::value || - std::is_base_of::value, + std::is_same_v || + std::is_base_of_v, std::bidirectional_iterator_tag, std::input_iterator_tag> enable_reverse; typedef typename diff --git a/ql/utilities/steppingiterator.hpp b/ql/utilities/steppingiterator.hpp index ae7b3e48f07..8bb658f35b0 100644 --- a/ql/utilities/steppingiterator.hpp +++ b/ql/utilities/steppingiterator.hpp @@ -61,8 +61,8 @@ namespace QuantLib { template step_iterator(const step_iterator& i, - std::enable_if_t::value>* = nullptr) + std::enable_if_t>* = nullptr) : base_(i.base_), step_(static_cast(i.step())) {} Size step() const { return static_cast(this->step_); } diff --git a/test-suite/digitaloption.cpp b/test-suite/digitaloption.cpp index 8eb5f334775..200993adb1d 100644 --- a/test-suite/digitaloption.cpp +++ b/test-suite/digitaloption.cpp @@ -22,6 +22,7 @@ #include "toplevelfixture.hpp" #include "utilities.hpp" +#include #include #include #include @@ -418,9 +419,9 @@ BOOST_AUTO_TEST_CASE(testCashAtExpiryOrNothingAmericanValues) { Handle(volTS))); ext::shared_ptr engine; if (value.knockin) - engine.reset(new AnalyticDigitalAmericanEngine(stochProcess)); + engine = ext::make_shared(stochProcess); else - engine.reset(new AnalyticDigitalAmericanKOEngine(stochProcess)); + engine = ext::make_shared(stochProcess); VanillaOption opt(payoff, amExercise); opt.setPricingEngine(engine); @@ -490,9 +491,9 @@ BOOST_AUTO_TEST_CASE(testAssetAtExpiryOrNothingAmericanValues) { Handle(volTS))); ext::shared_ptr engine; if (value.knockin) - engine.reset(new AnalyticDigitalAmericanEngine(stochProcess)); + engine = ext::make_shared(stochProcess); else - engine.reset(new AnalyticDigitalAmericanKOEngine(stochProcess)); + engine = ext::make_shared(stochProcess); VanillaOption opt(payoff, amExercise); opt.setPricingEngine(engine); diff --git a/test-suite/doublebinaryoption.cpp b/test-suite/doublebinaryoption.cpp index dff063fd5e6..1106657caf4 100644 --- a/test-suite/doublebinaryoption.cpp +++ b/test-suite/doublebinaryoption.cpp @@ -19,6 +19,7 @@ Copyright (C) 2015 Thema Consulting SA #include "toplevelfixture.hpp" #include "utilities.hpp" +#include #include #include #include @@ -194,9 +195,9 @@ BOOST_AUTO_TEST_CASE(testHaugValues) { Date exDate = today + timeToDays(value.t); ext::shared_ptr exercise; if (value.barrierType == DoubleBarrier::KIKO || value.barrierType == DoubleBarrier::KOKI) - exercise.reset(new AmericanExercise(today, exDate)); + exercise = ext::make_shared(today, exDate); else - exercise.reset(new EuropeanExercise(exDate)); + exercise = ext::make_shared(exDate); spot->setValue(value.s); qRate->setValue(value.q); From 5072f0e95c60000a0d2e8c9c7f33df3f4ec02669 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 15:15:29 +0200 Subject: [PATCH 6/7] Agree to disagree with clang-tidy --- .clang-tidy | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-tidy b/.clang-tidy index cbfdac63061..54244d3f793 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -55,6 +55,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, From ff8fa3609f722729923a11fe49588652c900e926 Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Mon, 19 Aug 2024 16:31:08 +0200 Subject: [PATCH 7/7] Silence a few more warnings --- .clang-tidy | 1 + ql/cashflow.cpp | 4 ++-- ql/experimental/callablebonds/treecallablebondengine.cpp | 2 +- ql/math/matrixutilities/tqreigendecomposition.cpp | 2 +- ql/version.hpp | 1 - 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 54244d3f793..fcd8d6f83bb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -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, diff --git a/ql/cashflow.cpp b/ql/cashflow.cpp index b6ecca631d9..a55efc0d19d 100644 --- a/ql/cashflow.cpp +++ b/ql/cashflow.cpp @@ -42,8 +42,8 @@ namespace QuantLib { // specified in the settings (if any) ext::optional includeToday = Settings::instance().includeTodaysCashFlows(); - if (includeToday) // NOLINT(readability-implicit-bool-conversion) - includeRefDate = *includeToday; + if (includeToday.has_value()) + includeRefDate = includeToday; } return Event::hasOccurred(refDate, includeRefDate); } diff --git a/ql/experimental/callablebonds/treecallablebondengine.cpp b/ql/experimental/callablebonds/treecallablebondengine.cpp index 0301a67c54a..cd0b563f095 100644 --- a/ql/experimental/callablebonds/treecallablebondengine.cpp +++ b/ql/experimental/callablebonds/treecallablebondengine.cpp @@ -44,7 +44,7 @@ namespace QuantLib { } void TreeCallableFixedRateBondEngine::calculate() const { - return calculateWithSpread(arguments_.spread); + calculateWithSpread(arguments_.spread); } void TreeCallableFixedRateBondEngine::calculateWithSpread(Spread s) const { diff --git a/ql/math/matrixutilities/tqreigendecomposition.cpp b/ql/math/matrixutilities/tqreigendecomposition.cpp index 13391d2be11..cb0fa294552 100644 --- a/ql/math/matrixutilities/tqreigendecomposition.cpp +++ b/ql/math/matrixutilities/tqreigendecomposition.cpp @@ -48,7 +48,7 @@ namespace QuantLib { for (Size k=n-1; k >=1; --k) { while (!offDiagIsZero(k, e)) { Size l = k; - while (--l > 0 && !offDiagIsZero(l,e)); + while (--l > 0 && !offDiagIsZero(l,e)); // NOLINT(bugprone-inc-dec-in-conditions) iter_++; Real q = d_[l]; diff --git a/ql/version.hpp b/ql/version.hpp index 734c3202313..68e741f066c 100644 --- a/ql/version.hpp +++ b/ql/version.hpp @@ -34,7 +34,6 @@ #define QL_VERSION "1.36-dev" //! version hexadecimal number -// NOLINTNEXTLINE(cppcoreguidelines-macro-to-enum) #define QL_HEX_VERSION 0x01360000 /*! @} */