From 3d0a15f009c233f44224fa81cc899025fa59d362 Mon Sep 17 00:00:00 2001 From: Chris Burel Date: Thu, 10 Feb 2022 13:24:27 -0800 Subject: [PATCH] Remove `AZStd::to_string(string&, bool)` overload from MCore's StringConversion header This overload has significant impact on overload resolution. Consider these overloads: ```cpp void to_string(AZStd::string& dest, AZStd::wstring_view src); void to_string(string& str, bool value); ``` And then calling code like this: ``` WCHAR src[260]; AZStd::string dst; AZStd::to_string(dst, src); // Which overload does this call? ``` If the .cpp has not included `MCore/Source/StringConversions.h`, the call to `to_string()` will convert the `WCHAR[260]` type to a `AZStd::wstring_view`, and call the first overload. But if `StringConversions.h` _has_ been included, the implicit conversion of `WCHAR[260]` to `bool` has a higher precedence, and it will be chosen instead. This overload was causing some uses of `to_string` in `AnimGraph/GameController.cpp` to resolve to the wrong overload in unity builds. Signed-off-by: Chris Burel --- Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp | 5 ----- Gems/EMotionFX/Code/MCore/Source/StringConversions.h | 2 -- 2 files changed, 7 deletions(-) diff --git a/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp b/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp index 88a22db245..5f57a036c2 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp +++ b/Gems/EMotionFX/Code/MCore/Source/StringConversions.cpp @@ -76,11 +76,6 @@ namespace MCore namespace AZStd { - void to_string(string& str, bool value) - { - str = value ? "true" : "false"; - } - void to_string(string& str, const AZ::Vector2& value) { str = AZStd::string::format("%.8f,%.8f", diff --git a/Gems/EMotionFX/Code/MCore/Source/StringConversions.h b/Gems/EMotionFX/Code/MCore/Source/StringConversions.h index fd1c59208d..01b41091cf 100644 --- a/Gems/EMotionFX/Code/MCore/Source/StringConversions.h +++ b/Gems/EMotionFX/Code/MCore/Source/StringConversions.h @@ -49,7 +49,6 @@ namespace MCore namespace AZStd { - void to_string(string& str, bool value); void to_string(string& str, const AZ::Vector2& value); void to_string(string& str, const AZ::Vector3& value); void to_string(string& str, const AZ::Vector4& value); @@ -57,7 +56,6 @@ namespace AZStd void to_string(string& str, const AZ::Matrix4x4& value); void to_string(string& str, const AZ::Transform& value); - inline AZStd::string to_string(bool val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(const AZ::Vector2& val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(const AZ::Vector3& val) { AZStd::string str; to_string(str, val); return str; } inline AZStd::string to_string(const AZ::Vector4& val) { AZStd::string str; to_string(str, val); return str; }