From 619baf0281711c0b93eb12159f236e976308f33f Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Sat, 6 Feb 2021 19:43:02 +0100 Subject: [PATCH 1/4] Add modernize-use-nullptr check --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index be095585bf8..59bec5eff43 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,5 +1,5 @@ --- -Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters' +Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,modernize-use-nullptr,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters' WarningsAsErrors: '' HeaderFilterRegex: '.*' AnalyzeTemporaryDtors: false From 2442dbe18e4c18bfe3c7dd30a7051c17d3497ca1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 6 Feb 2021 21:27:42 +0000 Subject: [PATCH 2/4] Automated fixes by clang-tidy --- Examples/GlobalOptimizer/GlobalOptimizer.cpp | 3 +- ql/cashflow.cpp | 2 +- ql/cashflows/averagebmacoupon.cpp | 2 +- ql/cashflows/capflooredcoupon.cpp | 2 +- ql/cashflows/capflooredcoupon.hpp | 4 +- ql/cashflows/capflooredinflationcoupon.cpp | 16 +++--- ql/cashflows/cashflows.cpp | 33 ++++++----- ql/cashflows/cmscoupon.cpp | 2 +- ql/cashflows/coupon.cpp | 2 +- ql/cashflows/couponpricer.cpp | 6 +- ql/cashflows/cpicoupon.cpp | 2 +- ql/cashflows/digitalcmscoupon.cpp | 2 +- ql/cashflows/digitalcoupon.cpp | 2 +- ql/cashflows/digitalcoupon.hpp | 4 +- ql/cashflows/digitaliborcoupon.cpp | 2 +- ql/cashflows/dividend.cpp | 2 +- ql/cashflows/fixedratecoupon.hpp | 2 +- ql/cashflows/floatingratecoupon.cpp | 4 +- ql/cashflows/floatingratecoupon.hpp | 2 +- ql/cashflows/iborcoupon.cpp | 2 +- ql/cashflows/indexedcashflow.hpp | 2 +- ql/cashflows/inflationcoupon.cpp | 4 +- ql/cashflows/inflationcoupon.hpp | 2 +- ql/cashflows/inflationcouponpricer.cpp | 2 +- ql/cashflows/lineartsrpricer.cpp | 2 +- ql/cashflows/overnightindexedcoupon.cpp | 2 +- ql/cashflows/rangeaccrual.cpp | 2 +- ql/cashflows/simplecashflow.hpp | 6 +- ql/cashflows/yoyinflationcoupon.cpp | 2 +- ql/currencies/exchangeratemanager.cpp | 4 +- ql/event.cpp | 2 +- .../averageois/arithmeticoisratehelper.cpp | 4 +- .../averageois/makearithmeticaverageois.cpp | 4 +- .../barrieroption/doublebarrieroption.cpp | 2 +- .../quantodoublebarrieroption.cpp | 3 +- ql/experimental/basismodels/swaptioncfs.cpp | 2 +- .../callablebonds/callablebond.cpp | 4 +- .../callablebonds/treecallablebondengine.cpp | 4 +- ql/experimental/catbonds/catbond.cpp | 4 +- .../commodities/commoditycashflow.cpp | 2 +- .../commodities/commoditycurve.cpp | 2 +- .../commodities/commoditycurve.hpp | 2 +- .../commodities/commodityindex.cpp | 4 +- .../commodities/commodityindex.hpp | 2 +- .../commodities/energycommodity.cpp | 10 ++-- .../convertiblebonds/convertiblebond.cpp | 4 +- ql/experimental/coupons/cmsspreadcoupon.cpp | 2 +- ql/experimental/coupons/cmsspreadcoupon.hpp | 2 +- .../coupons/digitalcmsspreadcoupon.cpp | 2 +- .../coupons/lognormalcmsspreadpricer.cpp | 2 +- .../coupons/strippedcapflooredcoupon.cpp | 7 +-- ql/experimental/coupons/subperiodcoupons.cpp | 2 +- ql/experimental/credit/basket.cpp | 8 +-- ql/experimental/credit/cdsoption.cpp | 4 +- ql/experimental/credit/defaultevent.cpp | 4 +- .../credit/defaultprobabilitylatentmodel.hpp | 2 +- ql/experimental/credit/nthtodefault.cpp | 4 +- ql/experimental/credit/syntheticcdo.cpp | 4 +- .../exoticoptions/complexchooseroption.cpp | 2 +- .../exoticoptions/compoundoption.cpp | 2 +- .../exoticoptions/everestoption.cpp | 5 +- .../exoticoptions/himalayaoption.cpp | 2 +- .../exoticoptions/holderextensibleoption.cpp | 2 +- .../exoticoptions/margrabeoption.cpp | 5 +- .../exoticoptions/pagodaoption.cpp | 2 +- .../partialtimebarrieroption.cpp | 2 +- .../exoticoptions/simplechooseroption.cpp | 2 +- .../exoticoptions/twoassetbarrieroption.cpp | 2 +- .../twoassetcorrelationoption.cpp | 2 +- .../exoticoptions/writerextensibleoption.cpp | 2 +- .../fdmblackscholesfwdop.cpp | 5 +- .../fdmexpextouinnervaluecalculator.hpp | 2 +- .../fdmextoujumpmodelinnervalue.hpp | 2 +- .../finitedifferences/fdmhestonfwdop.cpp | 16 ++---- .../finitedifferences/vanillavppoption.cpp | 2 +- .../overnightindexfutureratehelper.cpp | 2 +- .../math/hybridsimulatedannealing.hpp | 2 +- .../mcbasket/pathmultiassetoption.cpp | 4 +- ql/experimental/mcbasket/pathpayoff.hpp | 2 +- .../shortrate/generalizedhullwhite.hpp | 2 +- ql/experimental/swaptions/irregularswap.cpp | 4 +- .../swaptions/irregularswaption.cpp | 2 +- .../crosscurrencyratehelpers.cpp | 4 +- .../multicurvesensitivities.hpp | 2 +- .../integralhestonvarianceoptionengine.cpp | 2 +- .../varianceoption/varianceoption.cpp | 2 +- .../volatility/abcdatmvolcurve.cpp | 2 +- .../volatility/blackatmvolcurve.cpp | 2 +- .../volatility/blackvolsurface.cpp | 2 +- .../volatility/equityfxvolsurface.cpp | 2 +- .../volatility/extendedblackvariancecurve.hpp | 2 +- .../extendedblackvariancesurface.hpp | 2 +- .../volatility/interestratevolsurface.cpp | 2 +- ql/experimental/volatility/sabrvolsurface.cpp | 2 +- ql/instrument.hpp | 7 +-- ql/instruments/asianoption.cpp | 4 +- ql/instruments/assetswap.cpp | 6 +- ql/instruments/barrieroption.cpp | 2 +- ql/instruments/bond.cpp | 6 +- ql/instruments/callabilityschedule.hpp | 2 +- ql/instruments/capfloor.cpp | 4 +- ql/instruments/cliquetoption.cpp | 3 +- ql/instruments/cpicapfloor.cpp | 2 +- ql/instruments/cpiswap.cpp | 4 +- ql/instruments/creditdefaultswap.cpp | 4 +- ql/instruments/creditdefaultswap.hpp | 2 +- ql/instruments/dividendbarrieroption.cpp | 2 +- ql/instruments/dividendvanillaoption.cpp | 2 +- ql/instruments/floatfloatswap.cpp | 30 +++++----- ql/instruments/floatfloatswaption.cpp | 2 +- ql/instruments/forwardvanillaoption.cpp | 5 +- ql/instruments/impliedvolatility.cpp | 3 +- ql/instruments/inflationcapfloor.cpp | 2 +- ql/instruments/lookbackoption.cpp | 8 +-- ql/instruments/makecms.cpp | 2 +- ql/instruments/makeois.cpp | 4 +- ql/instruments/makevanillaswap.cpp | 4 +- ql/instruments/multiassetoption.cpp | 5 +- ql/instruments/nonstandardswap.cpp | 6 +- ql/instruments/nonstandardswaption.cpp | 2 +- ql/instruments/oneassetoption.cpp | 6 +- ql/instruments/payoffs.cpp | 18 +++--- ql/instruments/quantobarrieroption.cpp | 3 +- ql/instruments/quantoforwardvanillaoption.cpp | 3 +- ql/instruments/quantovanillaoption.cpp | 3 +- ql/instruments/stickyratchet.cpp | 2 +- ql/instruments/swap.cpp | 6 +- ql/instruments/swaption.cpp | 2 +- ql/instruments/vanillastorageoption.hpp | 2 +- ql/instruments/vanillaswap.cpp | 4 +- ql/instruments/vanillaswingoption.cpp | 4 +- ql/instruments/varianceswap.cpp | 2 +- ql/instruments/yearonyearinflationswap.cpp | 4 +- .../libormarketmodels/liborforwardmodel.cpp | 2 +- ql/math/array.hpp | 14 ++--- ql/math/integrals/gaussianquadratures.hpp | 4 +- ql/math/matrix.hpp | 22 ++++---- ql/math/matrixutilities/bicgstab.cpp | 4 +- ql/math/matrixutilities/gmres.cpp | 4 +- ql/math/optimization/lmdif.cpp | 2 +- ql/math/randomnumbers/latticerules.cpp | 4 +- ql/math/randomnumbers/seedgenerator.cpp | 2 +- .../finitedifferencemodel.hpp | 2 +- .../meshers/fdmblackscholesmesher.cpp | 2 +- .../meshers/fdmhestonvariancemesher.cpp | 2 +- .../operators/fdm2dblackscholesop.cpp | 7 +-- .../operators/fdmblackscholesop.cpp | 15 ++--- .../operators/fdmhestonop.cpp | 5 +- .../operators/fdmlocalvolfwdop.cpp | 2 +- .../solvers/fdmbackwardsolver.cpp | 2 +- .../finitedifferences/tridiagonaloperator.hpp | 2 +- .../utilities/fdmtimedepdirichletboundary.cpp | 7 +-- .../onefactormodels/gaussian1dmodel.cpp | 10 ++-- .../onefactormodels/gaussian1dmodel.hpp | 2 +- ql/models/shortrate/onefactormodels/gsr.cpp | 6 +- ql/option.hpp | 2 +- ql/patterns/observable.hpp | 6 +- ql/payoff.hpp | 2 +- ql/pricingengines/americanpayoffatexpiry.cpp | 4 +- ql/pricingengines/americanpayoffathit.cpp | 8 +-- .../barrier/analyticbinarybarrierengine.cpp | 4 +- .../basket/mcamericanbasketengine.cpp | 2 +- ql/pricingengines/basket/stulzengine.cpp | 4 +- .../capfloor/analyticcapfloorengine.cpp | 2 +- .../capfloor/gaussian1dcapfloorengine.cpp | 4 +- .../capfloor/treecapfloorengine.cpp | 4 +- ql/pricingengines/credit/isdacdsengine.cpp | 3 +- ql/pricingengines/swap/cvaswapengine.cpp | 4 +- ql/pricingengines/swap/treeswapengine.cpp | 4 +- .../swaption/basketgeneratingengine.cpp | 2 +- .../gaussian1dfloatfloatswaptionengine.cpp | 18 +++--- .../gaussian1dnonstandardswaptionengine.cpp | 2 +- .../swaption/jamshidianswaptionengine.cpp | 2 +- .../swaption/treeswaptionengine.cpp | 4 +- .../vanilla/analytichestonengine.cpp | 56 ++++++++----------- .../vanilla/analyticptdhestonengine.cpp | 2 +- .../vanilla/fddividendengine.hpp | 6 +- .../fdhestonhullwhitevanillaengine.cpp | 2 +- .../vanilla/fdhestonvanillaengine.cpp | 2 +- ql/pricingengines/vanilla/fdvanillaengine.cpp | 2 +- .../vanilla/mcamericanengine.cpp | 2 +- ql/processes/blackscholesprocess.cpp | 4 +- ql/termstructures/bootstraphelper.hpp | 8 +-- ql/termstructures/globalbootstrap.hpp | 16 +++--- ql/termstructures/inflationtermstructure.cpp | 2 +- ql/termstructures/iterativebootstrap.hpp | 16 ++++-- ql/termstructures/localbootstrap.hpp | 9 +-- .../andreasenhugevolatilityinterpl.cpp | 16 +++--- .../volatility/equityfx/blackconstantvol.hpp | 2 +- .../equityfx/blackvariancecurve.hpp | 2 +- .../equityfx/blackvariancesurface.hpp | 2 +- .../equityfx/blackvoltermstructure.hpp | 6 +- .../equityfx/impliedvoltermstructure.hpp | 2 +- .../volatility/equityfx/localconstantvol.hpp | 2 +- .../volatility/equityfx/localvolcurve.hpp | 2 +- .../volatility/equityfx/localvolsurface.cpp | 2 +- .../equityfx/localvoltermstructure.cpp | 2 +- .../volatility/gaussian1dsmilesection.cpp | 6 +- .../volatility/swaption/cmsmarket.cpp | 3 +- ql/termstructures/yield/bondhelpers.cpp | 8 +-- .../yield/nonlinearfittingmethods.cpp | 14 ++--- ql/termstructures/yield/oisratehelper.cpp | 8 +-- ql/termstructures/yield/ratehelpers.cpp | 24 ++++---- ql/utilities/clone.hpp | 4 +- test-suite/cashflows.cpp | 24 ++++---- test-suite/hestonmodel.cpp | 3 +- test-suite/inflationcpiswap.cpp | 6 +- test-suite/marketmodel.cpp | 53 +++++++++--------- 208 files changed, 491 insertions(+), 535 deletions(-) diff --git a/Examples/GlobalOptimizer/GlobalOptimizer.cpp b/Examples/GlobalOptimizer/GlobalOptimizer.cpp index 9730a771f5e..055c1dca44d 100644 --- a/Examples/GlobalOptimizer/GlobalOptimizer.cpp +++ b/Examples/GlobalOptimizer/GlobalOptimizer.cpp @@ -144,7 +144,8 @@ class TestFunction : public CostFunction { typedef ext::function RealFunc; typedef ext::function(const Array&)> ArrayFunc; explicit TestFunction(const RealFunc & f, const ArrayFunc & fs = ArrayFunc()) : f_(f), fs_(fs) {} - explicit TestFunction(Real(*f)(const Array&), Disposable(*fs)(const Array&) = NULL) : f_(f), fs_(fs) {} + explicit TestFunction(Real (*f)(const Array&), Disposable (*fs)(const Array&) = nullptr) + : f_(f), fs_(fs) {} ~TestFunction() override {} Real value(const Array& x) const override { return f_(x); } Disposable values(const Array& x) const override { diff --git a/ql/cashflow.cpp b/ql/cashflow.cpp index 431e6c483ad..0100bb4fc00 100644 --- a/ql/cashflow.cpp +++ b/ql/cashflow.cpp @@ -62,7 +62,7 @@ namespace QuantLib { void CashFlow::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else Event::accept(v); diff --git a/ql/cashflows/averagebmacoupon.cpp b/ql/cashflows/averagebmacoupon.cpp index 8250360043b..cee69922e9d 100644 --- a/ql/cashflows/averagebmacoupon.cpp +++ b/ql/cashflows/averagebmacoupon.cpp @@ -153,7 +153,7 @@ namespace QuantLib { void AverageBMACoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) { + if (v1 != nullptr) { v1->visit(*this); } else { FloatingRateCoupon::accept(v); diff --git a/ql/cashflows/capflooredcoupon.cpp b/ql/cashflows/capflooredcoupon.cpp index 05b602b72ea..d24a80b91f7 100644 --- a/ql/cashflows/capflooredcoupon.cpp +++ b/ql/cashflows/capflooredcoupon.cpp @@ -131,7 +131,7 @@ namespace QuantLib { void CappedFlooredCoupon::accept(AcyclicVisitor& v) { typedef FloatingRateCoupon super; auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else super::accept(v); diff --git a/ql/cashflows/capflooredcoupon.hpp b/ql/cashflows/capflooredcoupon.hpp index ef2f9ca326b..a73770afb5e 100644 --- a/ql/cashflows/capflooredcoupon.hpp +++ b/ql/cashflows/capflooredcoupon.hpp @@ -121,7 +121,7 @@ namespace QuantLib { void accept(AcyclicVisitor& v) override { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CappedFlooredCoupon::accept(v); @@ -153,7 +153,7 @@ namespace QuantLib { void accept(AcyclicVisitor& v) override { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CappedFlooredCoupon::accept(v); diff --git a/ql/cashflows/capflooredinflationcoupon.cpp b/ql/cashflows/capflooredinflationcoupon.cpp index be7aad66b24..5821375ba87 100644 --- a/ql/cashflows/capflooredinflationcoupon.cpp +++ b/ql/cashflows/capflooredinflationcoupon.cpp @@ -80,16 +80,17 @@ namespace QuantLib { const ext::shared_ptr& pricer) { YoYInflationCoupon::setPricer(pricer); - if (underlying_ != 0) + if (underlying_ != nullptr) underlying_->setPricer(pricer); } Rate CappedFlooredYoYInflationCoupon::rate() const { - Rate swapletRate = underlying_ != 0 ? underlying_->rate() : YoYInflationCoupon::rate(); + Rate swapletRate = + underlying_ != nullptr ? underlying_->rate() : YoYInflationCoupon::rate(); if(isFloored_ || isCapped_) { - if (underlying_ != 0) { + if (underlying_ != nullptr) { QL_REQUIRE(underlying_->pricer(), "pricer not set"); } else { QL_REQUIRE(pricer_, "pricer not set"); @@ -98,14 +99,15 @@ namespace QuantLib { Rate floorletRate = 0.; if(isFloored_) { - floorletRate = underlying_ != 0 ? + floorletRate = underlying_ != nullptr ? underlying_->pricer()->floorletRate(effectiveFloor()) : pricer()->floorletRate(effectiveFloor()); } Rate capletRate = 0.; if(isCapped_) { - capletRate = underlying_ != 0 ? underlying_->pricer()->capletRate(effectiveCap()) : - pricer()->capletRate(effectiveCap()); + capletRate = underlying_ != nullptr ? + underlying_->pricer()->capletRate(effectiveCap()) : + pricer()->capletRate(effectiveCap()); } return swapletRate + floorletRate - capletRate; @@ -149,7 +151,7 @@ namespace QuantLib { typedef YoYInflationCoupon super; auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else super::accept(v); diff --git a/ql/cashflows/cashflows.cpp b/ql/cashflows/cashflows.cpp index 70565563ec5..a64b00cbea7 100644 --- a/ql/cashflows/cashflows.cpp +++ b/ql/cashflows/cashflows.cpp @@ -40,7 +40,7 @@ namespace QuantLib { Date d = Date::maxDate(); for (Size i=0; i c = ext::dynamic_pointer_cast(leg[i]); - if (c != 0) + if (c != nullptr) d = std::min(d, c->accrualStartDate()); else d = std::min(d, leg[i]->date()); @@ -54,7 +54,7 @@ namespace QuantLib { Date d = Date::minDate(); for (Size i=0; i c = ext::dynamic_pointer_cast(leg[i]); - if (c != 0) + if (c != nullptr) d = std::max(d, c->accrualEndDate()); else d = std::max(d, leg[i]->date()); @@ -237,7 +237,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->nominal(); } return 0.0; @@ -252,7 +252,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accrualStartDate(); } return Date(); @@ -267,7 +267,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accrualEndDate(); } return Date(); @@ -282,7 +282,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->referencePeriodStart(); } return Date(); @@ -297,7 +297,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->referencePeriodEnd(); } return Date(); @@ -312,7 +312,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accrualPeriod(); } return 0; @@ -327,7 +327,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accrualDays(); } return 0; @@ -345,7 +345,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accruedPeriod(settlementDate); } return 0; @@ -363,7 +363,7 @@ namespace QuantLib { Date paymentDate = (*cf)->date(); for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) return cp->accruedDays(settlementDate); } return 0; @@ -382,7 +382,7 @@ namespace QuantLib { Real result = 0.0; for (; cfdate()==paymentDate; ++cf) { ext::shared_ptr cp = ext::dynamic_pointer_cast(*cf); - if (cp != 0) + if (cp != nullptr) result += cp->accruedAmount(settlementDate); } return result; @@ -491,7 +491,7 @@ namespace QuantLib { ext::dynamic_pointer_cast(leg[i]); Real df = discountCurve.discount(cf.date()); npv += cf.amount() * df; - if(cp != NULL) + if (cp != nullptr) bps += cp->nominal() * cp->accrualPeriod() * df; } } @@ -567,7 +567,7 @@ namespace QuantLib { Date refStartDate, refEndDate; ext::shared_ptr coupon = ext::dynamic_pointer_cast(cashFlow); - if (coupon != 0) { + if (coupon != nullptr) { refStartDate = coupon->referencePeriodStart(); refEndDate = coupon->referencePeriodEnd(); } else { @@ -581,14 +581,13 @@ namespace QuantLib { refEndDate = cashFlowDate; } - if ((coupon != 0) && lastDate != coupon->accrualStartDate()) { + if ((coupon != nullptr) && lastDate != coupon->accrualStartDate()) { Time couponPeriod = dc.yearFraction(coupon->accrualStartDate(), cashFlowDate, refStartDate, refEndDate); Time accruedPeriod = dc.yearFraction(coupon->accrualStartDate(), lastDate, refStartDate, refEndDate); return couponPeriod - accruedPeriod; - } - else { + } else { return dc.yearFraction(lastDate, cashFlowDate, refStartDate, refEndDate); } diff --git a/ql/cashflows/cmscoupon.cpp b/ql/cashflows/cmscoupon.cpp index 53de09284bd..92a30e50797 100644 --- a/ql/cashflows/cmscoupon.cpp +++ b/ql/cashflows/cmscoupon.cpp @@ -46,7 +46,7 @@ namespace QuantLib { void CmsCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else FloatingRateCoupon::accept(v); diff --git a/ql/cashflows/coupon.cpp b/ql/cashflows/coupon.cpp index ceef737f835..9d344615c64 100644 --- a/ql/cashflows/coupon.cpp +++ b/ql/cashflows/coupon.cpp @@ -76,7 +76,7 @@ namespace QuantLib { void Coupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CashFlow::accept(v); diff --git a/ql/cashflows/couponpricer.cpp b/ql/cashflows/couponpricer.cpp index 2032a1fb818..94cb7f06ea9 100644 --- a/ql/cashflows/couponpricer.cpp +++ b/ql/cashflows/couponpricer.cpp @@ -225,13 +225,13 @@ namespace QuantLib { // we might end up here because a CappedFlooredCoupon // was directly constructed; we should then check // the underlying for consistency with the pricer - if (ext::dynamic_pointer_cast(c.underlying()) != 0) { + if (ext::dynamic_pointer_cast(c.underlying()) != nullptr) { QL_REQUIRE(ext::dynamic_pointer_cast(pricer_), "pricer not compatible with Ibor Coupon"); - } else if (ext::dynamic_pointer_cast(c.underlying()) != 0) { + } else if (ext::dynamic_pointer_cast(c.underlying()) != nullptr) { QL_REQUIRE(ext::dynamic_pointer_cast(pricer_), "pricer not compatible with CMS Coupon"); - } else if (ext::dynamic_pointer_cast(c.underlying()) != 0) { + } else if (ext::dynamic_pointer_cast(c.underlying()) != nullptr) { QL_REQUIRE(ext::dynamic_pointer_cast(pricer_), "pricer not compatible with CMS spread Coupon"); } diff --git a/ql/cashflows/cpicoupon.cpp b/ql/cashflows/cpicoupon.cpp index 0d15517ada1..228ffad1d85 100644 --- a/ql/cashflows/cpicoupon.cpp +++ b/ql/cashflows/cpicoupon.cpp @@ -59,7 +59,7 @@ namespace QuantLib { void CPICoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else InflationCoupon::accept(v); diff --git a/ql/cashflows/digitalcmscoupon.cpp b/ql/cashflows/digitalcmscoupon.cpp index 82c8b41c7f9..fe07c5c70e0 100644 --- a/ql/cashflows/digitalcmscoupon.cpp +++ b/ql/cashflows/digitalcmscoupon.cpp @@ -43,7 +43,7 @@ namespace QuantLib { void DigitalCmsCoupon::accept(AcyclicVisitor& v) { typedef DigitalCoupon super; auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else super::accept(v); diff --git a/ql/cashflows/digitalcoupon.cpp b/ql/cashflows/digitalcoupon.cpp index 1d78c0a7bf5..206a37ce88f 100644 --- a/ql/cashflows/digitalcoupon.cpp +++ b/ql/cashflows/digitalcoupon.cpp @@ -282,7 +282,7 @@ namespace QuantLib { void DigitalCoupon::accept(AcyclicVisitor& v) { typedef FloatingRateCoupon super; auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else super::accept(v); diff --git a/ql/cashflows/digitalcoupon.hpp b/ql/cashflows/digitalcoupon.hpp index 250cc0a0312..4518fe00baf 100644 --- a/ql/cashflows/digitalcoupon.hpp +++ b/ql/cashflows/digitalcoupon.hpp @@ -131,10 +131,10 @@ namespace QuantLib { void accept(AcyclicVisitor&) override; void setPricer(const ext::shared_ptr& pricer) override { - if (pricer_ != 0) + if (pricer_ != nullptr) unregisterWith(pricer_); pricer_ = pricer; - if (pricer_ != 0) + if (pricer_ != nullptr) registerWith(pricer_); update(); underlying_->setPricer(pricer); diff --git a/ql/cashflows/digitaliborcoupon.cpp b/ql/cashflows/digitaliborcoupon.cpp index 4aae26b629a..3877fac2b2a 100644 --- a/ql/cashflows/digitaliborcoupon.cpp +++ b/ql/cashflows/digitaliborcoupon.cpp @@ -43,7 +43,7 @@ namespace QuantLib { void DigitalIborCoupon::accept(AcyclicVisitor& v) { typedef DigitalCoupon super; auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else super::accept(v); diff --git a/ql/cashflows/dividend.cpp b/ql/cashflows/dividend.cpp index 50a0ff816b2..07673fe7a79 100644 --- a/ql/cashflows/dividend.cpp +++ b/ql/cashflows/dividend.cpp @@ -25,7 +25,7 @@ namespace QuantLib { void Dividend::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CashFlow::accept(v); diff --git a/ql/cashflows/fixedratecoupon.hpp b/ql/cashflows/fixedratecoupon.hpp index a9ed5f659dd..7836b50074a 100644 --- a/ql/cashflows/fixedratecoupon.hpp +++ b/ql/cashflows/fixedratecoupon.hpp @@ -123,7 +123,7 @@ namespace QuantLib { inline void FixedRateCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else Coupon::accept(v); diff --git a/ql/cashflows/floatingratecoupon.cpp b/ql/cashflows/floatingratecoupon.cpp index a005db934b8..f82c32bb664 100644 --- a/ql/cashflows/floatingratecoupon.cpp +++ b/ql/cashflows/floatingratecoupon.cpp @@ -60,10 +60,10 @@ namespace QuantLib { void FloatingRateCoupon::setPricer( const ext::shared_ptr& pricer) { - if (pricer_ != 0) + if (pricer_ != nullptr) unregisterWith(pricer_); pricer_ = pricer; - if (pricer_ != 0) + if (pricer_ != nullptr) registerWith(pricer_); update(); } diff --git a/ql/cashflows/floatingratecoupon.hpp b/ql/cashflows/floatingratecoupon.hpp index e6c69d4f8ca..e6d8e3a2043 100644 --- a/ql/cashflows/floatingratecoupon.hpp +++ b/ql/cashflows/floatingratecoupon.hpp @@ -144,7 +144,7 @@ namespace QuantLib { inline void FloatingRateCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else Coupon::accept(v); diff --git a/ql/cashflows/iborcoupon.cpp b/ql/cashflows/iborcoupon.cpp index 24e90891aa5..abf6033a726 100644 --- a/ql/cashflows/iborcoupon.cpp +++ b/ql/cashflows/iborcoupon.cpp @@ -143,7 +143,7 @@ namespace QuantLib { void IborCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else FloatingRateCoupon::accept(v); diff --git a/ql/cashflows/indexedcashflow.hpp b/ql/cashflows/indexedcashflow.hpp index c9d761bdc06..6a0bb79835c 100644 --- a/ql/cashflows/indexedcashflow.hpp +++ b/ql/cashflows/indexedcashflow.hpp @@ -88,7 +88,7 @@ namespace QuantLib { inline void IndexedCashFlow::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CashFlow::accept(v); diff --git a/ql/cashflows/inflationcoupon.cpp b/ql/cashflows/inflationcoupon.cpp index f4681d126f7..80403693266 100644 --- a/ql/cashflows/inflationcoupon.cpp +++ b/ql/cashflows/inflationcoupon.cpp @@ -49,10 +49,10 @@ namespace QuantLib { void InflationCoupon::setPricer(const ext::shared_ptr& pricer) { QL_REQUIRE(checkPricerImpl(pricer),"pricer given is wrong type"); - if (pricer_ != 0) + if (pricer_ != nullptr) unregisterWith(pricer_); pricer_ = pricer; - if (pricer_ != 0) + if (pricer_ != nullptr) registerWith(pricer_); update(); } diff --git a/ql/cashflows/inflationcoupon.hpp b/ql/cashflows/inflationcoupon.hpp index 90cbf90d26e..bb05991ffbc 100644 --- a/ql/cashflows/inflationcoupon.hpp +++ b/ql/cashflows/inflationcoupon.hpp @@ -117,7 +117,7 @@ namespace QuantLib { inline void InflationCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else Coupon::accept(v); diff --git a/ql/cashflows/inflationcouponpricer.cpp b/ql/cashflows/inflationcouponpricer.cpp index 2b0264853dc..cb82ca5d256 100644 --- a/ql/cashflows/inflationcouponpricer.cpp +++ b/ql/cashflows/inflationcouponpricer.cpp @@ -28,7 +28,7 @@ namespace QuantLib { for (Size i=0; i c = ext::dynamic_pointer_cast(leg[i]); - if (c != 0) + if (c != nullptr) c->setPricer(p); } } diff --git a/ql/cashflows/lineartsrpricer.cpp b/ql/cashflows/lineartsrpricer.cpp index 7fe06ea52ac..e2ee38d8aea 100644 --- a/ql/cashflows/lineartsrpricer.cpp +++ b/ql/cashflows/lineartsrpricer.cpp @@ -62,7 +62,7 @@ namespace QuantLib { if (!couponDiscountCurve_.empty()) registerWith(couponDiscountCurve_); - if (integrator_ == NULL) + if (integrator_ == nullptr) integrator_ = ext::make_shared(1E-10, 5000, 1E-10); } diff --git a/ql/cashflows/overnightindexedcoupon.cpp b/ql/cashflows/overnightindexedcoupon.cpp index f8c633e1d9e..604e610fab3 100644 --- a/ql/cashflows/overnightindexedcoupon.cpp +++ b/ql/cashflows/overnightindexedcoupon.cpp @@ -206,7 +206,7 @@ namespace QuantLib { void OvernightIndexedCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) { + if (v1 != nullptr) { v1->visit(*this); } else { FloatingRateCoupon::accept(v); diff --git a/ql/cashflows/rangeaccrual.cpp b/ql/cashflows/rangeaccrual.cpp index e18c7400995..903a9903f21 100644 --- a/ql/cashflows/rangeaccrual.cpp +++ b/ql/cashflows/rangeaccrual.cpp @@ -85,7 +85,7 @@ namespace QuantLib { void RangeAccrualFloatersCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else FloatingRateCoupon::accept(v); diff --git a/ql/cashflows/simplecashflow.hpp b/ql/cashflows/simplecashflow.hpp index d3fa82d953e..29c0278b3d1 100644 --- a/ql/cashflows/simplecashflow.hpp +++ b/ql/cashflows/simplecashflow.hpp @@ -89,7 +89,7 @@ namespace QuantLib { inline void SimpleCashFlow::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else CashFlow::accept(v); @@ -97,7 +97,7 @@ namespace QuantLib { inline void Redemption::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else SimpleCashFlow::accept(v); @@ -105,7 +105,7 @@ namespace QuantLib { inline void AmortizingPayment::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else SimpleCashFlow::accept(v); diff --git a/ql/cashflows/yoyinflationcoupon.cpp b/ql/cashflows/yoyinflationcoupon.cpp index c95b5d90a7f..f5298851abb 100644 --- a/ql/cashflows/yoyinflationcoupon.cpp +++ b/ql/cashflows/yoyinflationcoupon.cpp @@ -46,7 +46,7 @@ namespace QuantLib { void YoYInflationCoupon::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else InflationCoupon::accept(v); diff --git a/ql/currencies/exchangeratemanager.cpp b/ql/currencies/exchangeratemanager.cpp index 47d6304c72b..b625a95b39b 100644 --- a/ql/currencies/exchangeratemanager.cpp +++ b/ql/currencies/exchangeratemanager.cpp @@ -195,9 +195,7 @@ namespace QuantLib { const Date& date) const { const std::list& rates = data_[hash(source,target)]; auto i = std::find_if(rates.begin(), rates.end(), valid_at(date)); - return i == rates.end() ? - (const ExchangeRate*) 0 : - &(i->rate); + return i == rates.end() ? (const ExchangeRate*)nullptr : &(i->rate); } } diff --git a/ql/event.cpp b/ql/event.cpp index 5d82468cf0d..a5edf97fa2c 100644 --- a/ql/event.cpp +++ b/ql/event.cpp @@ -39,7 +39,7 @@ namespace QuantLib { void Event::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else QL_FAIL("not an event visitor"); diff --git a/ql/experimental/averageois/arithmeticoisratehelper.cpp b/ql/experimental/averageois/arithmeticoisratehelper.cpp index 3c6524ea2f8..e3fb59b1cfe 100644 --- a/ql/experimental/averageois/arithmeticoisratehelper.cpp +++ b/ql/experimental/averageois/arithmeticoisratehelper.cpp @@ -89,7 +89,7 @@ namespace QuantLib { } Real ArithmeticOISRateHelper::impliedQuote() const { - QL_REQUIRE(termStructure_ != 0, "term structure not set"); + QL_REQUIRE(termStructure_ != nullptr, "term structure not set"); // we didn't register as observers - force calculation swap_->recalculate(); //return swap_->fairRate(); @@ -105,7 +105,7 @@ namespace QuantLib { void ArithmeticOISRateHelper::accept(AcyclicVisitor& v) { auto* v1 = dynamic_cast*>(&v); - if (v1 != 0) + if (v1 != nullptr) v1->visit(*this); else RateHelper::accept(v); diff --git a/ql/experimental/averageois/makearithmeticaverageois.cpp b/ql/experimental/averageois/makearithmeticaverageois.cpp index 71e7ad26879..f34de7cf5bc 100644 --- a/ql/experimental/averageois/makearithmeticaverageois.cpp +++ b/ql/experimental/averageois/makearithmeticaverageois.cpp @@ -110,7 +110,7 @@ namespace QuantLib { overnightLegSchedule, overnightSpread_, mrs_, vol_, byApprox_); - if (engine_ == 0) { + if (engine_ == nullptr) { Handle disc = overnightIndex_->forwardingTermStructure(); QL_REQUIRE(!disc.empty(), @@ -135,7 +135,7 @@ namespace QuantLib { overnightSpread_, mrs_, vol_, byApprox_)); - if (engine_ == 0) { + if (engine_ == nullptr) { Handle disc = overnightIndex_->forwardingTermStructure(); bool includeSettlementDateFlows = false; diff --git a/ql/experimental/barrieroption/doublebarrieroption.cpp b/ql/experimental/barrieroption/doublebarrieroption.cpp index 938296b805c..e6758f81d84 100644 --- a/ql/experimental/barrieroption/doublebarrieroption.cpp +++ b/ql/experimental/barrieroption/doublebarrieroption.cpp @@ -41,7 +41,7 @@ namespace QuantLib { OneAssetOption::setupArguments(args); auto* moreArgs = dynamic_cast(args); - QL_REQUIRE(moreArgs != 0, "wrong argument type"); + QL_REQUIRE(moreArgs != nullptr, "wrong argument type"); moreArgs->barrierType = barrierType_; moreArgs->barrier_lo = barrier_lo_; moreArgs->barrier_hi = barrier_hi_; diff --git a/ql/experimental/barrieroption/quantodoublebarrieroption.cpp b/ql/experimental/barrieroption/quantodoublebarrieroption.cpp index 6051c89829e..34108211e9e 100644 --- a/ql/experimental/barrieroption/quantodoublebarrieroption.cpp +++ b/ql/experimental/barrieroption/quantodoublebarrieroption.cpp @@ -60,8 +60,7 @@ namespace QuantLib { const PricingEngine::results* r) const { DoubleBarrierOption::fetchResults(r); const auto* quantoResults = dynamic_cast(r); - QL_ENSURE(quantoResults != 0, - "no quanto results returned from pricing engine"); + QL_ENSURE(quantoResults != nullptr, "no quanto results returned from pricing engine"); qrho_ = quantoResults->qrho; qvega_ = quantoResults->qvega; qlambda_ = quantoResults->qlambda; diff --git a/ql/experimental/basismodels/swaptioncfs.cpp b/ql/experimental/basismodels/swaptioncfs.cpp index a677f69ebd3..7781a1a3411 100644 --- a/ql/experimental/basismodels/swaptioncfs.cpp +++ b/ql/experimental/basismodels/swaptioncfs.cpp @@ -109,7 +109,7 @@ namespace QuantLib { fixedWeights_.push_back(fixedLeg_[k]->amount()); for (Size k = 0; k < fixedLeg_.size(); ++k) { ext::shared_ptr coupon = ext::dynamic_pointer_cast(fixedLeg_[k]); - if (coupon != 0) + if (coupon != nullptr) annuityWeights_.push_back(coupon->nominal() * coupon->accrualPeriod()); } } diff --git a/ql/experimental/callablebonds/callablebond.cpp b/ql/experimental/callablebonds/callablebond.cpp index 4eca9c6d78a..17fa9c2212d 100644 --- a/ql/experimental/callablebonds/callablebond.cpp +++ b/ql/experimental/callablebonds/callablebond.cpp @@ -418,7 +418,7 @@ namespace QuantLib { if (!cashflows_[i]->hasOccurred(settlement,IncludeToday)) { ext::shared_ptr coupon = ext::dynamic_pointer_cast(cashflows_[i]); - if (coupon != 0) + if (coupon != nullptr) // !!! return coupon->accruedAmount(settlement) / notional(settlement) * 100.0; @@ -437,7 +437,7 @@ namespace QuantLib { auto* arguments = dynamic_cast(args); - QL_REQUIRE(arguments != 0, "no arguments given"); + QL_REQUIRE(arguments != nullptr, "no arguments given"); Date settlement = arguments->settlementDate; diff --git a/ql/experimental/callablebonds/treecallablebondengine.cpp b/ql/experimental/callablebonds/treecallablebondengine.cpp index 26779430b5d..4626e708955 100644 --- a/ql/experimental/callablebonds/treecallablebondengine.cpp +++ b/ql/experimental/callablebonds/treecallablebondengine.cpp @@ -53,7 +53,7 @@ namespace QuantLib { ext::shared_ptr tsmodel = ext::dynamic_pointer_cast(*model_); Handle discountCurve = - tsmodel != 0 ? tsmodel->termStructure() : termStructure_; + tsmodel != nullptr ? tsmodel->termStructure() : termStructure_; Date referenceDate = discountCurve->referenceDate(); DayCounter dayCounter = discountCurve->dayCounter(); @@ -63,7 +63,7 @@ namespace QuantLib { dayCounter); ext::shared_ptr lattice; - if (lattice_ != 0) { + if (lattice_ != nullptr) { lattice = lattice_; } else { std::vector