Merge pull request #5713 from akva2/fmt_fix_runtime_formats

fixed: use constexpr formats and/or mark format strings runtime
This commit is contained in:
Bård Skaflestad 2024-11-05 15:59:40 +01:00 committed by GitHub
commit 2546d2b181
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 18 deletions

View File

@ -21,7 +21,6 @@
#include "config.h" #include "config.h"
#endif // HAVE_CONFIG_H #endif // HAVE_CONFIG_H
#include <map>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
@ -36,20 +35,13 @@
#include <opm/input/eclipse/Parser/ParseContext.hpp> #include <opm/input/eclipse/Parser/ParseContext.hpp>
#include <opm/simulators/flow/KeywordValidation.hpp> #include <opm/simulators/flow/KeywordValidation.hpp>
namespace Opm namespace Opm::KeywordValidation {
{
namespace KeywordValidation
{
std::string get_error_report(const std::vector<ValidationError>& errors, const bool include_noncritical, const bool include_critical) std::string get_error_report(const std::vector<ValidationError>& errors, const bool include_noncritical, const bool include_critical)
{ {
const std::string keyword_format = " {keyword}: keyword not supported\n"; const std::string keyword_format = " {keyword}: keyword not supported\n";
const std::string item_format1 = " {{keyword}}: invalid value '{}' for item {}\n"; constexpr std::string_view item_format1 = " {{keyword}}: invalid value '{}' for item {}\n";
const std::string item_format2 = " {{keyword}}: invalid value '{}' in record {} for item {}\n"; constexpr std::string_view item_format2 = " {{keyword}}: invalid value '{}' in record {} for item {}\n";
const std::string location_format = " In file: {file}, line {line}\n"; const std::string location_format = " In file: {file}, line {line}\n";
std::string report; std::string report;
@ -206,7 +198,4 @@ namespace KeywordValidation
} }
} }
} // namespace Opm::KeywordValidation
} // namespace KeywordValidation
} // namespace Opm

View File

@ -421,8 +421,8 @@ void GasLiftSingleWellGeneric<Scalar>::
debugShowBhpAlqTable_() debugShowBhpAlqTable_()
{ {
Scalar alq = 0.0; Scalar alq = 0.0;
const std::string fmt_fmt1 {"{:^12s} {:^12s} {:^12s} {:^12s}"}; constexpr std::string_view fmt_fmt1 {"{:^12s} {:^12s} {:^12s} {:^12s}"};
const std::string fmt_fmt2 {"{:>12.5g} {:>12.5g} {:>12.5g} {:>12.5g}"}; constexpr std::string_view fmt_fmt2 {"{:>12.5g} {:>12.5g} {:>12.5g} {:>12.5g}"};
const std::string header = fmt::format(fmt_fmt1, "ALQ", "BHP", "oil", "gas"); const std::string header = fmt::format(fmt_fmt1, "ALQ", "BHP", "oil", "gas");
displayDebugMessage_(header); displayDebugMessage_(header);
auto max_it = 50; auto max_it = 50;

View File

@ -330,7 +330,7 @@ addPrintMessage(const std::string& msg,
this->group_.name() this->group_.name()
); );
const std::string measure_name(this->unit_system_.name(measure)); const std::string measure_name(this->unit_system_.name(measure));
const std::string message = fmt::format(msg, const std::string message = fmt::format(fmt::runtime(msg),
this->unit_system_.from_si(measure, value), measure_name, this->unit_system_.from_si(measure, value), measure_name,
this->unit_system_.from_si(measure, limit), measure_name); this->unit_system_.from_si(measure, limit), measure_name);