From a2e4bc5291381df0d995d50f4243528dad5f83ec Mon Sep 17 00:00:00 2001 From: Luigi Ballabio Date: Tue, 26 Sep 2023 16:53:44 +0200 Subject: [PATCH] Avoid a few new warnings Hopefully, they're false positives. Tests run correctly. --- .../BermudanSwaption/BermudanSwaption.cpp | 11 ++++++++++ .../calibrationhelpers/swaptionhelper.cpp | 9 ++++++++ test-suite/bermudanswaption.cpp | 21 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/Examples/BermudanSwaption/BermudanSwaption.cpp b/Examples/BermudanSwaption/BermudanSwaption.cpp index e256ca93866..c2d83c37122 100644 --- a/Examples/BermudanSwaption/BermudanSwaption.cpp +++ b/Examples/BermudanSwaption/BermudanSwaption.cpp @@ -171,6 +171,12 @@ int main(int, char* []) { Size j = numCols - i -1; // 1x5, 2x4, 3x3, 4x2, 5x1 Size k = i*numCols + j; auto vol = ext::make_shared(swaptionVols[k]); + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + swaptions.push_back(ext::make_shared( swaptionMaturities[i], Period(swapLengths[j], Years), @@ -180,6 +186,11 @@ int main(int, char* []) { indexSixMonths->dayCounter(), indexSixMonths->dayCounter(), rhTermStructure)); + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif + swaptions.back()->addTimesTo(times); } diff --git a/ql/models/shortrate/calibrationhelpers/swaptionhelper.cpp b/ql/models/shortrate/calibrationhelpers/swaptionhelper.cpp index feb4b658aef..fbd60b4e6c4 100644 --- a/ql/models/shortrate/calibrationhelpers/swaptionhelper.cpp +++ b/ql/models/shortrate/calibrationhelpers/swaptionhelper.cpp @@ -191,8 +191,17 @@ namespace QuantLib { ext::shared_ptr exercise(new EuropeanExercise(exerciseDate)); +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + swaption_ = ext::make_shared(swap_, exercise); +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif + BlackCalibrationHelper::performCalculations(); } diff --git a/test-suite/bermudanswaption.cpp b/test-suite/bermudanswaption.cpp index 5b5c997318d..9f56e3b3e62 100644 --- a/test-suite/bermudanswaption.cpp +++ b/test-suite/bermudanswaption.cpp @@ -263,8 +263,19 @@ void BermudanSwaptionTest::testCachedG2Values() { for (const auto& i : swap->fixedLeg()) { exerciseDates.push_back(ext::dynamic_pointer_cast(i)->accrualStartDate()); } + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + swaptions.push_back(ext::make_shared(swap, ext::make_shared(exerciseDates))); + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif + } const Real a=0.1, sigma=0.01, b=0.2, eta=0.013, rho=-0.5; @@ -343,8 +354,18 @@ void BermudanSwaptionTest::testTreeEngineTimeSnapping() { auto callDate = initialCallDate + i * Days; if (calendar.isBusinessDay(callDate)) { + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#endif + auto bermudanSwaption = makeBermudanSwaption(callDate); +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#endif + auto model = ext::make_shared(termStructure); bermudanSwaption->setPricingEngine(ext::make_shared(model));