Skip to content

Commit

Permalink
Remove undefined behavior from debug_settings_manager.cpp
Browse files Browse the repository at this point in the history
It is undefined behavior to add definition of function overload to std
namespace.

Signed-off-by: Patryk Wrobel <patryk.wrobel@intel.com>
  • Loading branch information
PatrykWrobelDev authored and Compute-Runtime-Automation committed Sep 5, 2022
1 parent 12c7f32 commit 09bb076
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions shared/source/debug_settings/debug_settings_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
#include <fstream>
#include <iostream>
#include <sstream>

namespace std {
static std::string to_string(const std::string &arg) { // NOLINT(readability-identifier-naming)
return arg;
}
} // namespace std
#include <type_traits>

namespace NEO {

template <typename T>
static std::string toString(const T &arg) {
if constexpr (std::is_convertible_v<std::string, T>) {
return static_cast<std::string>(arg);
} else {
return std::to_string(arg);
}
}

template <DebugFunctionalityLevel DebugLevel>
DebugSettingsManager<DebugLevel>::DebugSettingsManager(const char *registryPath) {
readerImpl = SettingsReaderCreator::create(std::string(registryPath));
Expand Down Expand Up @@ -58,7 +62,7 @@ template <DebugFunctionalityLevel DebugLevel>
template <typename DataType>
void DebugSettingsManager<DebugLevel>::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());
}
}
Expand Down

0 comments on commit 09bb076

Please sign in to comment.