From 62dfa617494716076e8e9a331a25f9418120a03b Mon Sep 17 00:00:00 2001 From: MiguelBarro <45819833+MiguelBarro@users.noreply.github.com> Date: Thu, 13 Jul 2023 15:57:20 +0200 Subject: [PATCH 1/5] fixing std::shared_ptr initialization from void* class `shared_ptr` is optimized to avoid keeping a deleter object for non-primitive types which are detected using `_Can_scalar_delete`. This class relies on SFINAE to detect if the operator delete is valid for a given pointer type. It turns out that delete a void* is valid in msvc, though, according to the standard is undefined behaviour (7.6.2.9). By specializing for void is possible to prevent direct initialization of `shared_ptr` from a void* and prevent bugs. Note that `default_deleter` is not valid too. --- stl/inc/memory | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/inc/memory b/stl/inc/memory index 5ed5de5528..c10d179c97 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1486,6 +1486,8 @@ template struct _Can_scalar_delete : false_type {}; template struct _Can_scalar_delete<_Yty, void_t())>> : true_type {}; +template<> +struct _Can_scalar_delete : false_type {}; template struct _Can_array_delete : false_type {}; From 1f9e4e53342e47de5dfb553099fd067cfc4dcea3 Mon Sep 17 00:00:00 2001 From: MiguelBarro <45819833+MiguelBarro@users.noreply.github.com> Date: Thu, 13 Jul 2023 16:05:49 +0200 Subject: [PATCH 2/5] Fix format issues --- stl/inc/memory | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/memory b/stl/inc/memory index c10d179c97..7958f31404 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1486,7 +1486,7 @@ template struct _Can_scalar_delete : false_type {}; template struct _Can_scalar_delete<_Yty, void_t())>> : true_type {}; -template<> +template <> struct _Can_scalar_delete : false_type {}; template From baa367b666d7fe696863120defb0d6592e9a0842 Mon Sep 17 00:00:00 2001 From: MiguelBarro <45819833+MiguelBarro@users.noreply.github.com> Date: Thu, 13 Jul 2023 23:45:36 +0200 Subject: [PATCH 3/5] handling cv qualifiers on void Sticking to metaprogramming available in C++14 --- stl/inc/memory | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 7958f31404..86dd103f1e 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1485,9 +1485,8 @@ private: template struct _Can_scalar_delete : false_type {}; template -struct _Can_scalar_delete<_Yty, void_t())>> : true_type {}; -template <> -struct _Can_scalar_delete : false_type {}; +struct _Can_scalar_delete<_Yty, void_t())>> + : std::integral_constant::value)> {}; template struct _Can_array_delete : false_type {}; From 345a5c04d9613abfbb6845ef68e106ac4594cd55 Mon Sep 17 00:00:00 2001 From: MiguelBarro <45819833+MiguelBarro@users.noreply.github.com> Date: Thu, 13 Jul 2023 23:54:11 +0200 Subject: [PATCH 4/5] adjust style avoid using resolution for std namespace types --- stl/inc/memory | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/memory b/stl/inc/memory index 86dd103f1e..8334de317a 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1486,7 +1486,7 @@ template struct _Can_scalar_delete : false_type {}; template struct _Can_scalar_delete<_Yty, void_t())>> - : std::integral_constant::value)> {}; + : integral_constant::value)> {}; template struct _Can_array_delete : false_type {}; From 27b006e4868bc4d43ed30204c69512ef80611f21 Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 13 Jul 2023 15:09:20 -0700 Subject: [PATCH 5/5] Tiny style cleanup --- stl/inc/memory | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stl/inc/memory b/stl/inc/memory index 8334de317a..1ab7c06089 100644 --- a/stl/inc/memory +++ b/stl/inc/memory @@ -1485,8 +1485,7 @@ private: template struct _Can_scalar_delete : false_type {}; template -struct _Can_scalar_delete<_Yty, void_t())>> - : integral_constant::value)> {}; +struct _Can_scalar_delete<_Yty, void_t())>> : bool_constant> {}; template struct _Can_array_delete : false_type {};