Skip to content

Commit 09bb076

Browse files
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 <patryk.wrobel@intel.com>
1 parent 12c7f32 commit 09bb076

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

shared/source/debug_settings/debug_settings_manager.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
#include <fstream>
1919
#include <iostream>
2020
#include <sstream>
21-
22-
namespace std {
23-
static std::string to_string(const std::string &arg) { // NOLINT(readability-identifier-naming)
24-
return arg;
25-
}
26-
} // namespace std
21+
#include <type_traits>
2722

2823
namespace NEO {
2924

25+
template <typename T>
26+
static std::string toString(const T &arg) {
27+
if constexpr (std::is_convertible_v<std::string, T>) {
28+
return static_cast<std::string>(arg);
29+
} else {
30+
return std::to_string(arg);
31+
}
32+
}
33+
3034
template <DebugFunctionalityLevel DebugLevel>
3135
DebugSettingsManager<DebugLevel>::DebugSettingsManager(const char *registryPath) {
3236
readerImpl = SettingsReaderCreator::create(std::string(registryPath));
@@ -58,7 +62,7 @@ template <DebugFunctionalityLevel DebugLevel>
5862
template <typename DataType>
5963
void DebugSettingsManager<DebugLevel>::dumpNonDefaultFlag(const char *variableName, const DataType &variableValue, const DataType &defaultValue) {
6064
if (variableValue != defaultValue) {
61-
const auto variableStringValue = std::to_string(variableValue);
65+
const auto variableStringValue = toString(variableValue);
6266
PRINT_DEBUG_STRING(true, stdout, "Non-default value of debug variable: %s = %s\n", variableName, variableStringValue.c_str());
6367
}
6468
}

0 commit comments

Comments
 (0)