From 09bb0766e207803a16edbd8ae4c4ddf492ca1709 Mon Sep 17 00:00:00 2001 From: Patryk Wrobel Date: Mon, 5 Sep 2022 17:20:23 +0000 Subject: [PATCH] Remove undefined behavior from debug_settings_manager.cpp It is undefined behavior to add definition of function overload to std namespace. Signed-off-by: Patryk Wrobel --- .../debug_settings/debug_settings_manager.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/shared/source/debug_settings/debug_settings_manager.cpp b/shared/source/debug_settings/debug_settings_manager.cpp index 5d585eb2b75b4..24feb8511ada1 100644 --- a/shared/source/debug_settings/debug_settings_manager.cpp +++ b/shared/source/debug_settings/debug_settings_manager.cpp @@ -18,15 +18,19 @@ #include #include #include - -namespace std { -static std::string to_string(const std::string &arg) { // NOLINT(readability-identifier-naming) - return arg; -} -} // namespace std +#include namespace NEO { +template +static std::string toString(const T &arg) { + if constexpr (std::is_convertible_v) { + return static_cast(arg); + } else { + return std::to_string(arg); + } +} + template DebugSettingsManager::DebugSettingsManager(const char *registryPath) { readerImpl = SettingsReaderCreator::create(std::string(registryPath)); @@ -58,7 +62,7 @@ template template void DebugSettingsManager::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue) { if (variableValue != defaultValue) { - const auto variableStringValue = std::to_string(variableValue); + const auto variableStringValue = toString(variableValue); PRINT_DEBUG_STRING(true, stdout, "Non-default value of debug variable: %s = %s\n", variableName, variableStringValue.c_str()); } }