Skip to content

Commit

Permalink
Enable C4127 at W3 warning level (#2045)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Jul 29, 2024
2 parents 5772848 + df04c16 commit 2230bcc
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 70 deletions.
13 changes: 6 additions & 7 deletions cmake/Platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ if (MSVC)
# /wd26812
# Suppress warnings: "Prefer enum class over enum" (Enum.3)

add_compile_options(/wd4267 /wd4819 /wd26812)
# /w34127
# Enable warning under W3: conditional expression is constant

# prevent warnings when using /std:c++17 and above
if(CMAKE_CXX_STANDARD GREATER_EQUAL 17)
# E.g. caused by #include <boost/numeric/ublas/matrix.hpp>
# In c++17 std::iterator is deprecated. As of boost 1.81 boost::ublas has not provided a fix for this.
add_compile_definitions(_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING)
endif()
add_compile_options(/wd4267 /wd4819 /wd26812 /w34127)

# Silence all C++17 deprecation warnings, same as in the vcxproj files
add_compile_definitions(_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)
endif()
6 changes: 3 additions & 3 deletions ql/experimental/barrieroption/mcdoublebarrierengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/exoticoptions/mceverestengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace QuantLib {
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();

if (RNG::allowsErrorEstimate) {
if constexpr (RNG::allowsErrorEstimate) {
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down
6 changes: 3 additions & 3 deletions ql/experimental/exoticoptions/mchimalayaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ namespace QuantLib {
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();

if (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/exoticoptions/mcpagodaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down
12 changes: 6 additions & 6 deletions ql/experimental/mcbasket/mclongstaffschwartzpathengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace QuantLib {
void calculate() const;

protected:
virtual ext::shared_ptr<LongstaffSchwartzMultiPathPricer>
virtual ext::shared_ptr<LongstaffSchwartzMultiPathPricer>
lsmPathPricer() const = 0;

TimeGrid timeGrid() const;
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace QuantLib {
"timeSteps must be positive, " << timeSteps <<
" not allowed");
QL_REQUIRE(timeStepsPerYear != 0,
"timeStepsPerYear must be positive, "
"timeStepsPerYear must be positive, "
<< timeStepsPerYear << " not allowed");
this->registerWith(process_);
}
Expand All @@ -122,7 +122,7 @@ namespace QuantLib {
inline
ext::shared_ptr<typename
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::path_pricer_type>
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::pathPricer()
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::pathPricer()
const {

QL_REQUIRE(pathPricer_, "path pricer unknown");
Expand All @@ -132,7 +132,7 @@ namespace QuantLib {
template <class GenericEngine, template <class> class MC,
class RNG, class S>
inline
void MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::calculate()
void MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::calculate()
const {
pathPricer_ = this->lsmPathPricer();
this->mcModel_ = ext::shared_ptr<MonteCarloModel<MC,RNG,S> >(
Expand All @@ -147,7 +147,7 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
this->results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate) {
if constexpr (RNG::allowsErrorEstimate) {
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace QuantLib {
inline
ext::shared_ptr<typename
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::path_generator_type>
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::pathGenerator()
MCLongstaffSchwartzPathEngine<GenericEngine,MC,RNG,S>::pathGenerator()
const {

Size dimensions = process_->factors();
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/mcbasket/mcpathbasketengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down
6 changes: 3 additions & 3 deletions ql/pricingengines/asian/mcdiscreteasianenginebase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ namespace QuantLib {
}

results_.value = this->mcModel_->sampleAccumulator().mean();

if (this->controlVariate_) {
// control variate might lead to small negative
// option values for deep OTM options
this->results_.value = std::max(0.0, this->results_.value);
}
if (RNG::allowsErrorEstimate)

if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();

Expand Down
6 changes: 3 additions & 3 deletions ql/pricingengines/barrier/mcbarrierengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down
6 changes: 3 additions & 3 deletions ql/pricingengines/basket/mceuropeanbasketengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down
3 changes: 1 addition & 2 deletions ql/pricingengines/capfloor/mchullwhiteengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down Expand Up @@ -248,4 +248,3 @@ namespace QuantLib {


#endif

6 changes: 3 additions & 3 deletions ql/pricingengines/cliquet/mcperformanceengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down
8 changes: 4 additions & 4 deletions ql/pricingengines/forward/mcforwardvanillaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
this->results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down Expand Up @@ -176,4 +176,4 @@ namespace QuantLib {
}


#endif
#endif
2 changes: 1 addition & 1 deletion ql/pricingengines/forward/mcvarianceswapengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace QuantLib {
results_.value =
multiplier * (results_.variance - arguments_.strike);

if (RNG::allowsErrorEstimate) {
if constexpr (RNG::allowsErrorEstimate) {
Real varianceError =
this->mcModel_->sampleAccumulator().errorEstimate();
results_.errorEstimate = multiplier * varianceError;
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/lookback/mclookbackengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
this->results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
if constexpr (RNG::allowsErrorEstimate)
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/mclongstaffschwartzengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ namespace QuantLib {
this->results_.value = this->mcModel_->sampleAccumulator().mean();
this->results_.additionalResults["exerciseProbability"] =
this->pathPricer_->exerciseProbability();
if (RNG::allowsErrorEstimate) {
if constexpr (RNG::allowsErrorEstimate) {
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}
Expand Down
6 changes: 3 additions & 3 deletions ql/pricingengines/vanilla/mcvanillaengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace QuantLib {
requiredSamples_,
maxSamples_);
this->results_.value = this->mcModel_->sampleAccumulator().mean();
if (RNG::allowsErrorEstimate)
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
if constexpr (RNG::allowsErrorEstimate)
this->results_.errorEstimate =
this->mcModel_->sampleAccumulator().errorEstimate();
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion test-suite/andreasenhugevolatilityinterpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ CalibrationData AndreasenHugeExampleData() {
const Size nStrikes = LENGTH(raw);
const Size nMaturities = LENGTH(maturityTimes);

QL_REQUIRE(nMaturities == LENGTH(raw[1])-1, "check raw data");
static_assert(nMaturities == LENGTH(raw[1])-1, "check raw data");

AndreasenHugeVolatilityInterpl::CalibrationSet calibrationSet;

Expand Down
Loading

0 comments on commit 2230bcc

Please sign in to comment.