Bugfix: Avoid possible use of out-of-scope temporary.

Since std::clamp returns a reference we must be careful to not capture
the return value by reference, when there is a temporary among the input
parameters.

For the second change (adding the explicit Scalar return type to a lambda)
this is strictly speaking not necessary, as the lambda's return type is not
a reference, but that is obscure so the change is just done as to clarify.
This commit is contained in:
Atgeirr Flø Rasmussen
2024-05-28 16:01:48 +02:00
parent c84f14042d
commit 0fe76f6011
2 changed files with 2 additions and 2 deletions

View File

@@ -70,7 +70,7 @@ Scalar relaxationFactorFraction(const Scalar old_value,
const std::string msg = fmt::format(" illegal fraction value {} {} is found for well {}", value_name, old_value, well_name);
OPM_DEFLOG_PROBLEM(Opm::NumericalProblem, msg, deferred_logger);
}
const Scalar& safe_old_value = std::clamp(old_value, Scalar{0.0}, Scalar{1.0});
const Scalar safe_old_value = std::clamp(old_value, Scalar{0.0}, Scalar{1.0});
Scalar relaxation_factor = 1.;