From 87364bf8f6c71f478188f558ca692163f9ecfe8b Mon Sep 17 00:00:00 2001 From: Andrzej Kotulski Date: Thu, 2 Feb 2017 05:19:32 -0800 Subject: [PATCH] [C++ models] Fix compilation errors with make_shared/unique Summary: Some classes may have deleted new operator for them. To fix it, run global `new` operator instead ``` struct X { void* operator new(size_t) = delete; }; X *p = new X; // compilation error X *p = ::new X; // no compilation error ``` This change is following same strategy standard headers follow. Reviewed By: jvillard Differential Revision: D4500977 fbshipit-source-id: 20babfa --- infer/models/cpp/include/infer_model/shared_ptr.h | 2 +- infer/models/cpp/include/infer_model/unique_ptr.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/infer/models/cpp/include/infer_model/shared_ptr.h b/infer/models/cpp/include/infer_model/shared_ptr.h index 50bab7872..d9a07b0b6 100644 --- a/infer/models/cpp/include/infer_model/shared_ptr.h +++ b/infer/models/cpp/include/infer_model/shared_ptr.h @@ -405,7 +405,7 @@ class enable_shared_from_this : public std__enable_shared_from_this { template shared_ptr make_shared(Args&&... args) { - return shared_ptr(new T(std::forward(args)...)); + return shared_ptr(::new T(std::forward(args)...)); } #undef __cast_to_infer_ptr diff --git a/infer/models/cpp/include/infer_model/unique_ptr.h b/infer/models/cpp/include/infer_model/unique_ptr.h index e1f1eab09..683c549f3 100644 --- a/infer/models/cpp/include/infer_model/unique_ptr.h +++ b/infer/models/cpp/include/infer_model/unique_ptr.h @@ -446,13 +446,13 @@ struct _MakeUniq2<_Tp[_Bound]> { template inline typename _MakeUniq2<_Tp>::__single_object make_unique( _Args&&... __args) { - return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); + return unique_ptr<_Tp>(::new _Tp(std::forward<_Args>(__args)...)); } /// std::make_unique for arrays of unknown bound template inline typename _MakeUniq2<_Tp>::__array make_unique(size_t __num) { - return unique_ptr<_Tp>(new typename remove_extent<_Tp>::type[__num]()); + return unique_ptr<_Tp>(::new typename remove_extent<_Tp>::type[__num]()); } /// Disable std::make_unique for arrays of known bound