Skip to content

Commit

Permalink
Unsuppress bugprone-multiple-new-in-one-expression (#1758)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Aug 4, 2023
2 parents 82597fe + 34e18b4 commit 94eae2c
Show file tree
Hide file tree
Showing 28 changed files with 104 additions and 126 deletions.
8 changes: 5 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Checks: >
-bugprone-empty-catch,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-macro-parentheses,
-bugprone-multiple-new-in-one-expression,
-bugprone-narrowing-conversions,
-bugprone-non-zero-enum-to-bool-conversion,
-bugprone-suspicious-include,
Expand Down Expand Up @@ -48,7 +47,6 @@ Checks: >
modernize-*,
-modernize-avoid-c-arrays,
-modernize-macro-to-enum,
-modernize-make-shared,
-modernize-return-braced-init-list,
-modernize-use-emplace,
-modernize-use-trailing-return-type,
Expand All @@ -73,10 +71,14 @@ Checks: >
-readability-suspicious-call-argument,
-readability-use-anyofallof,
HeaderFilterRegex: '.*'
FormatStyle: file
FormatStyle: none
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: modernize-make-shared.MakeSmartPtrFunction
value: ext::make_shared
- key: modernize-make-shared.MakeSmartPtrFunctionHeader
value: <ql/shared_ptr.hpp>
- key: modernize-use-default-member-init.UseAssignment
value: 1
...
2 changes: 1 addition & 1 deletion Examples/Bonds/Bonds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ int main(int, char* []) {
floatingRateBond.setPricingEngine(bondEngine);

// Coupon pricers
ext::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer);
auto pricer = ext::make_shared<BlackIborCouponPricer>();

// optionLet volatilities
Volatility volatility = 0.0;
Expand Down
6 changes: 3 additions & 3 deletions Examples/CDS/CDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,11 @@ std::copy(cdsSchedule.begin(), cdsSchedule.end(),
Schedule sched( Date(22,September,2014), Date(20,December,2019), 3*Months,
WeekendsOnly(), Following, Unadjusted, DateGeneration::CDS, false, Date(), Date() );
ext::shared_ptr<CreditDefaultSwap> trade =
ext::shared_ptr<CreditDefaultSwap>(
new CreditDefaultSwap(Protection::Buyer, 100000000.0, 0.01, sched,
ext::make_shared<CreditDefaultSwap>(
Protection::Buyer, 100000000.0, 0.01, sched,
Following, Actual360(), true, true,
Date(22,October,2014), ext::shared_ptr<Claim>(),
Actual360(true), true));
Actual360(true), true);

ext::shared_ptr<FixedRateCoupon> cp = ext::dynamic_pointer_cast<FixedRateCoupon>(trade->coupons()[0]);
std::cout << "first period = " << cp->accrualStartDate() << " to " << cp->accrualEndDate() <<
Expand Down
8 changes: 2 additions & 6 deletions Examples/ConvertibleBonds/ConvertibleBonds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,8 @@ int main(int, char* []) {
new BlackConstantVol(settlementDate, calendar,
volatility, dayCounter)));


ext::shared_ptr<BlackScholesMertonProcess> stochasticProcess(
new BlackScholesMertonProcess(underlyingH,
flatDividendTS,
flatTermStructure,
flatVolTS));
auto stochasticProcess = ext::make_shared<BlackScholesMertonProcess>(
underlyingH, flatDividendTS, flatTermStructure, flatVolTS);

Size timeSteps = 801;

Expand Down
5 changes: 2 additions & 3 deletions Examples/EquityOption/EquityOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ int main(int, char* []) {
dayCounter)));
ext::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(type, strike));
ext::shared_ptr<BlackScholesMertonProcess> bsmProcess(
new BlackScholesMertonProcess(underlyingH, flatDividendTS,
flatTermStructure, flatVolTS));
auto bsmProcess = ext::make_shared<BlackScholesMertonProcess>(
underlyingH, flatDividendTS, flatTermStructure, flatVolTS);

// options
VanillaOption europeanOption(payoff, europeanExercise);
Expand Down
2 changes: 1 addition & 1 deletion Examples/Gaussian1dModels/Gaussian1dModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ int main(int argc, char *argv[]) {
const Leg &leg1 = underlying4->leg(1);
ext::shared_ptr<CmsCouponPricer> cmsPricer =
ext::make_shared<LinearTsrPricer>(swaptionVol, reversionQuote);
ext::shared_ptr<IborCouponPricer> iborPricer(new BlackIborCouponPricer);
auto iborPricer = ext::make_shared<BlackIborCouponPricer>();

setCouponPricer(leg0, cmsPricer);
setCouponPricer(leg1, iborPricer);
Expand Down
5 changes: 2 additions & 3 deletions Examples/Replication/Replication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ int main(int, char* []) {
ext::shared_ptr<StrikedTypePayoff> payoff(
new PlainVanillaPayoff(type, strike));

ext::shared_ptr<BlackScholesProcess> bsProcess(
new BlackScholesProcess(Handle<Quote>(underlying),
flatRate, flatVol));
auto bsProcess = ext::make_shared<BlackScholesProcess>(
Handle<Quote>(underlying), flatRate, flatVol);

ext::shared_ptr<PricingEngine> barrierEngine(
new AnalyticBarrierEngine(bsProcess));
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/digitalcmscoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace QuantLib {
bool isPutATMIncluded = false,
Rate putDigitalPayoff = Null<Rate>(),
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication),
ext::make_shared<DigitalReplication>(),
bool nakedOption = false);

//! \name Visitability
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace QuantLib {
DigitalCmsLeg& withPutPayoffs(const std::vector<Rate>& payoffs);
DigitalCmsLeg& withReplication(
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication));
ext::make_shared<DigitalReplication>());
DigitalCmsLeg& withNakedOption(bool nakedOption = true);

operator Leg() const;
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/digitaliborcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace QuantLib {
bool isPutATMIncluded = false,
Rate putDigitalPayoff = Null<Rate>(),
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication),
ext::make_shared<DigitalReplication>(),
bool nakedOption =false);

//! \name Visitability
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace QuantLib {
DigitalIborLeg& withPutPayoffs(const std::vector<Rate>& payoffs);
DigitalIborLeg &withReplication(
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication));
ext::make_shared<DigitalReplication>());
DigitalIborLeg& withNakedOption(bool nakedOption = true);

operator Leg() const;
Expand Down
8 changes: 4 additions & 4 deletions ql/experimental/basismodels/tenorswaptionvts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ namespace QuantLib {
swapRateTarg_ = targSwap->fairRate();
swapRateFinl_ = finlSwap->fairRate();
SwaptionCashFlows cfs(
ext::shared_ptr<Swaption>(new Swaption(
baseSwap, ext::shared_ptr<Exercise>(new EuropeanExercise(exerciseDate)))),
ext::make_shared<Swaption>(
baseSwap, ext::shared_ptr<Exercise>(new EuropeanExercise(exerciseDate))),
volTS.discountCurve_);
SwaptionCashFlows cf2(
ext::shared_ptr<Swaption>(new Swaption(
targSwap, ext::shared_ptr<Exercise>(new EuropeanExercise(exerciseDate)))),
ext::make_shared<Swaption>(
targSwap, ext::shared_ptr<Exercise>(new EuropeanExercise(exerciseDate))),
volTS.discountCurve_);
// calculate affine TSR model u and v
// Sum tau_j (fixed leg)
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/coupons/digitalcmsspreadcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace QuantLib {
bool isPutATMIncluded = false,
Rate putDigitalPayoff = Null<Rate>(),
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication),
ext::make_shared<DigitalReplication>(),
bool nakedOption = false);

//! \name Visitability
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace QuantLib {
DigitalCmsSpreadLeg& withPutPayoffs(const std::vector<Rate>& payoffs);
DigitalCmsSpreadLeg& withReplication(
const ext::shared_ptr<DigitalReplication> &replication =
ext::shared_ptr<DigitalReplication>(new DigitalReplication));
ext::make_shared<DigitalReplication>());
DigitalCmsSpreadLeg& withNakedOption(bool nakedOption = true);

operator Leg() const;
Expand Down
8 changes: 4 additions & 4 deletions ql/experimental/coupons/lognormalcmsspreadpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,19 @@ namespace QuantLib {
<< ") should be positive while gearing2 ("
<< gearing2_ << ") should be negative");

c1_ = ext::shared_ptr<CmsCoupon>(new CmsCoupon(
c1_ = ext::make_shared<CmsCoupon>(
coupon_->date(), coupon_->nominal(), coupon_->accrualStartDate(),
coupon_->accrualEndDate(), coupon_->fixingDays(),
index_->swapIndex1(), 1.0, 0.0, coupon_->referencePeriodStart(),
coupon_->referencePeriodEnd(), coupon_->dayCounter(),
coupon_->isInArrears()));
coupon_->isInArrears());

c2_ = ext::shared_ptr<CmsCoupon>(new CmsCoupon(
c2_ = ext::make_shared<CmsCoupon>(
coupon_->date(), coupon_->nominal(), coupon_->accrualStartDate(),
coupon_->accrualEndDate(), coupon_->fixingDays(),
index_->swapIndex2(), 1.0, 0.0, coupon_->referencePeriodStart(),
coupon_->referencePeriodEnd(), coupon_->dayCounter(),
coupon_->isInArrears()));
coupon_->isInArrears());

c1_->setPricer(cmsPricer_);
c2_->setPricer(cmsPricer_);
Expand Down
5 changes: 2 additions & 3 deletions ql/experimental/credit/riskyassetswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ namespace QuantLib {
floatConvention_, floatConvention_,
DateGeneration::Forward, false);

asw_ = ext::shared_ptr<RiskyAssetSwap>(
new RiskyAssetSwap(true,
asw_ = ext::make_shared<RiskyAssetSwap>(true,
100.0,
fixedSchedule,
floatSchedule,
Expand All @@ -258,7 +257,7 @@ namespace QuantLib {
0.01,
recoveryRate_,
yieldTS_,
probability_));
probability_);
}

}
8 changes: 4 additions & 4 deletions ql/experimental/swaptions/haganirregularswaptionengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ namespace QuantLib {
QL_REQUIRE(coupon, "dynamic cast of float leg coupon failed.");

if (coupon->date() <= expiries_[i]) {
ext::shared_ptr<IborCoupon> newCpn = ext::shared_ptr<IborCoupon>(new IborCoupon(
ext::shared_ptr<IborCoupon> newCpn = ext::make_shared<IborCoupon>(
coupon->date(), 1.0, coupon->accrualStartDate(), coupon->accrualEndDate(),
coupon->fixingDays(), coupon->iborIndex(), 1.0, coupon->spread(),
coupon->referencePeriodStart(), coupon->referencePeriodEnd(),
coupon->dayCounter(), coupon->isInArrears()));
coupon->dayCounter(), coupon->isInArrears());


if (!newCpn->isInArrears())
Expand Down Expand Up @@ -257,11 +257,11 @@ namespace QuantLib {
ext::shared_ptr<IborCoupon> coupon = ext::dynamic_pointer_cast<IborCoupon>(j);
QL_REQUIRE(coupon, "dynamic cast of float leg coupon failed.");

ext::shared_ptr<IborCoupon> newCpn = ext::shared_ptr<IborCoupon>(new IborCoupon(
ext::shared_ptr<IborCoupon> newCpn = ext::make_shared<IborCoupon>(
coupon->date(), coupon->nominal(), coupon->accrualStartDate(),
coupon->accrualEndDate(), coupon->fixingDays(), coupon->iborIndex(),
coupon->gearing(), 0.0, coupon->referencePeriodStart(),
coupon->referencePeriodEnd(), coupon->dayCounter(), coupon->isInArrears()));
coupon->referencePeriodEnd(), coupon->dayCounter(), coupon->isInArrears());


if (!newCpn->isInArrears())
Expand Down
25 changes: 10 additions & 15 deletions ql/indexes/swapindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ namespace QuantLib {
SwapIndex::clone(const Handle<YieldTermStructure>& forwarding) const {

if (exogenousDiscount_)
return ext::shared_ptr<SwapIndex>(new
SwapIndex(familyName(),
return ext::make_shared<SwapIndex>(familyName(),
tenor(),
fixingDays(),
currency(),
Expand All @@ -122,25 +121,23 @@ namespace QuantLib {
fixedLegConvention(),
dayCounter(),
iborIndex_->clone(forwarding),
discount_));
discount_);
else
return ext::shared_ptr<SwapIndex>(new
SwapIndex(familyName(),
return ext::make_shared<SwapIndex>(familyName(),
tenor(),
fixingDays(),
currency(),
fixingCalendar(),
fixedLegTenor(),
fixedLegConvention(),
dayCounter(),
iborIndex_->clone(forwarding)));
iborIndex_->clone(forwarding));
}

ext::shared_ptr<SwapIndex>
SwapIndex::clone(const Handle<YieldTermStructure>& forwarding,
const Handle<YieldTermStructure>& discounting) const {
return ext::shared_ptr<SwapIndex>(new
SwapIndex(familyName(),
return ext::make_shared<SwapIndex>(familyName(),
tenor(),
fixingDays(),
currency(),
Expand All @@ -149,15 +146,14 @@ namespace QuantLib {
fixedLegConvention(),
dayCounter(),
iborIndex_->clone(forwarding),
discounting));
discounting);
}

ext::shared_ptr<SwapIndex>
SwapIndex::clone(const Period& tenor) const {

if (exogenousDiscount_)
return ext::shared_ptr<SwapIndex>(new
SwapIndex(familyName(),
return ext::make_shared<SwapIndex>(familyName(),
tenor,
fixingDays(),
currency(),
Expand All @@ -166,18 +162,17 @@ namespace QuantLib {
fixedLegConvention(),
dayCounter(),
iborIndex(),
discountingTermStructure()));
discountingTermStructure());
else
return ext::shared_ptr<SwapIndex>(new
SwapIndex(familyName(),
return ext::make_shared<SwapIndex>(familyName(),
tenor,
fixingDays(),
currency(),
fixingCalendar(),
fixedLegTenor(),
fixedLegConvention(),
dayCounter(),
iborIndex()));
iborIndex());

}

Expand Down
4 changes: 2 additions & 2 deletions ql/instruments/makecds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ namespace QuantLib {
Unadjusted, rule_, false);

ext::shared_ptr<CreditDefaultSwap> cds =
ext::shared_ptr<CreditDefaultSwap>(new CreditDefaultSwap(
ext::make_shared<CreditDefaultSwap>(
side_, nominal_, upfrontRate_, couponRate_, schedule, Following,
dayCounter_, true, true, protectionStart, upfrontDate,
ext::shared_ptr<Claim>(), lastPeriodDayCounter_, true, tradeDate, cashSettlementDays_));
ext::shared_ptr<Claim>(), lastPeriodDayCounter_, true, tradeDate, cashSettlementDays_);

cds->setPricingEngine(engine_);
return cds;
Expand Down
8 changes: 4 additions & 4 deletions ql/pricingengines/swaption/basketgeneratingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace QuantLib {
atmVol = sec->volatility(atmStrike);
Real shift = sec->shift();

helper = ext::shared_ptr<SwaptionHelper>(new SwaptionHelper(
helper = ext::make_shared<SwaptionHelper>(
expiry, underlyingLastDate(),
Handle<Quote>(ext::make_shared<SimpleQuote>(atmVol)),
standardSwapBase->iborIndex(),
Expand All @@ -98,7 +98,7 @@ namespace QuantLib {
? standardSwapBase->discountingTermStructure()
: standardSwapBase->forwardingTermStructure(),
BlackCalibrationHelper::RelativePriceError, Null<Real>(), 1.0,
swaptionVolatility->volatilityType() ,shift));
swaptionVolatility->volatilityType() ,shift);

break;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ namespace QuantLib {

Real vol = sec->volatility(solution[2]);

helper = ext::shared_ptr<SwaptionHelper>(new SwaptionHelper(
helper = ext::make_shared<SwaptionHelper>(
expiry, matPeriod,
Handle<Quote>(ext::make_shared<SimpleQuote>(
vol)),
Expand All @@ -227,7 +227,7 @@ namespace QuantLib {
? standardSwapBase->discountingTermStructure()
: standardSwapBase->forwardingTermStructure(),
BlackCalibrationHelper::RelativePriceError, solution[2],
fabs(solution[0]), swaptionVolatility->volatilityType(), shift));
fabs(solution[0]), swaptionVolatility->volatilityType(), shift);
break;
}

Expand Down
Loading

0 comments on commit 94eae2c

Please sign in to comment.