diff --git a/src/cpp-utils/pointer/gcc_4_8_compatibility.h b/src/cpp-utils/pointer/gcc_4_8_compatibility.h index bf228c13..843ba2c0 100644 --- a/src/cpp-utils/pointer/gcc_4_8_compatibility.h +++ b/src/cpp-utils/pointer/gcc_4_8_compatibility.h @@ -7,10 +7,38 @@ #if __GNUC__ == 4 && __GNUC_MINOR__ == 8 // Add std::make_unique namespace std { - template - inline unique_ptr make_unique(Args&&... args) { - return unique_ptr(new T(std::forward(args)...)); - } + /// Alias template for remove_extent + template + using remove_extent_t = typename remove_extent<_Tp>::type; + + template + struct _MakeUniq + { typedef unique_ptr<_Tp> __single_object; }; + + template + struct _MakeUniq<_Tp[]> + { typedef unique_ptr<_Tp[]> __array; }; + + template + struct _MakeUniq<_Tp[_Bound]> + { struct __invalid_type { }; }; + + /// std::make_unique for single objects + template + inline typename _MakeUniq<_Tp>::__single_object + make_unique(_Args&&... __args) + { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); } + + /// std::make_unique for arrays of unknown bound + template + inline typename _MakeUniq<_Tp>::__array + make_unique(size_t __num) + { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); } + + /// Disable std::make_unique for arrays of known bound + template + inline typename _MakeUniq<_Tp>::__invalid_type + make_unique(_Args&&...) = delete; } #endif diff --git a/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.cpp b/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.cpp index abf443ec..70c78947 100644 --- a/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.cpp +++ b/test/blobstore/implementations/onblocks/testutils/BlobStoreTest.cpp @@ -2,6 +2,7 @@ #include #include "blobstore/implementations/onblocks/BlobStoreOnBlocks.h" +#include using blobstore::onblocks::BlobStoreOnBlocks; using blockstore::testfake::FakeBlockStore; diff --git a/test/cpp-utils/system/MemoryTest.cpp b/test/cpp-utils/system/MemoryTest.cpp index eb875962..6327b113 100644 --- a/test/cpp-utils/system/MemoryTest.cpp +++ b/test/cpp-utils/system/MemoryTest.cpp @@ -1,6 +1,7 @@ #include #include #include +#include using cpputils::DontSwapMemoryRAII;