From 11810d849baee1fbd03ed6023f2cc7279a88138f Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Fri, 13 Jan 2017 05:59:49 -0800 Subject: [PATCH] [C++] Fix compilation with enable_shared_from_this Summary: Fixes issue with template argument deduction with enable_shared_from_this as argument ``` #include template void makeWeak(const std::shared_ptr& x) {} struct X : public std::enable_shared_from_this{ }; void test() { X x makeWeak(x.shared_from_this()); // compilation failed here - it was unable to deduce template parameter of makeWeak } ``` Reviewed By: jvillard Differential Revision: D4414788 fbshipit-source-id: 4d19c53 --- .../cpp/include/infer_model/begin_name_override.inc | 1 + .../cpp/include/infer_model/end_name_override.inc | 1 + infer/models/cpp/include/infer_model/shared_ptr.h | 11 +++++++++++ 3 files changed, 13 insertions(+) diff --git a/infer/models/cpp/include/infer_model/begin_name_override.inc b/infer/models/cpp/include/infer_model/begin_name_override.inc index 9c48c48de..9d91583d1 100644 --- a/infer/models/cpp/include/infer_model/begin_name_override.inc +++ b/infer/models/cpp/include/infer_model/begin_name_override.inc @@ -1,4 +1,5 @@ #define make_shared std__make_shared +#define enable_shared_from_this std__enable_shared_from_this #define shared_ptr std__shared_ptr #define unique_ptr std__unique_ptr #define make_unique std__make_unique diff --git a/infer/models/cpp/include/infer_model/end_name_override.inc b/infer/models/cpp/include/infer_model/end_name_override.inc index f91c269d6..d55d48847 100644 --- a/infer/models/cpp/include/infer_model/end_name_override.inc +++ b/infer/models/cpp/include/infer_model/end_name_override.inc @@ -1,4 +1,5 @@ #undef make_shared +#undef enable_shared_from_this #undef shared_ptr #undef unique_ptr #undef make_unique diff --git a/infer/models/cpp/include/infer_model/shared_ptr.h b/infer/models/cpp/include/infer_model/shared_ptr.h index f51ecbc66..50bab7872 100644 --- a/infer/models/cpp/include/infer_model/shared_ptr.h +++ b/infer/models/cpp/include/infer_model/shared_ptr.h @@ -392,6 +392,17 @@ shared_ptr const_pointer_cast(shared_ptr const& r) noexcept { return const_pointer_cast((const std__shared_ptr&)r); } +template +class enable_shared_from_this : public std__enable_shared_from_this { + public: + shared_ptr shared_from_this() { + return std__enable_shared_from_this::shared_from_this(); + } + shared_ptr shared_from_this() const { + return std__enable_shared_from_this::shared_from_this(); + } +}; + template shared_ptr make_shared(Args&&... args) { return shared_ptr(new T(std::forward(args)...));