[PATCH] D48753: [libcxx] Use custom allocator's `construct` in C++03 when available.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 11 17:19:34 PST 2018


vsapsai marked 3 inline comments as done.
vsapsai added a comment.

Regarding the tests. I've moved most of new tests for custom allocators to test/libcxx/*. And in destroy.pass.cpp I'm just checking `_LIBCPP_VERSION` to avoid copying the test to a different file.



================
Comment at: libcxx/include/memory:1466
+template <class _Alloc, class _Pointer, class _Tp>
+struct __has_construct<_Alloc, _Pointer, _Tp, typename enable_if<
+    is_same
----------------
ldionne wrote:
> You can just say
> 
> ```
> template <class _Alloc, class _Pointer, class _Tp>
> struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
>     decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
> >::type> : std::true_type { };
> ```
Done. One of the reasons to use `is_same` was to mimic `__has_construct` for C++11 and later. But I don't think there is really value in keeping that.


================
Comment at: libcxx/include/memory:1726
+#else  // _LIBCPP_HAS_NO_VARIADICS
+    template <class _Tp, class _A0>
+        _LIBCPP_INLINE_VISIBILITY
----------------
ldionne wrote:
> Here,
> 
> ```
> template <class _Tp, class _A0, class = typename enable_if<__has_construct<allocator_type, _Tp*, _A0 const&>::value>::type>
> static void __construct(...);
> ```
> 
> and then below
> 
> ```
> template <class _Tp, class _A0, class = typename enable_if<!__has_construct<allocator_type, _Tp*, _A0 const&>::value>::type>
> static void __construct(...);
> ```
> 
> This way you don't have to call `__has_construct` at the point of call and `__construct` is slightly more reusable.
> 
I've tried that (also updated how `static void construct` calls `__construct`) and it works with C++2a but fails with C++03. The error is

```
llvm-project/libcxx/include/memory:1725:21: error: class member cannot be redeclared
        static void __construct(allocator_type&, _Tp* __p, const _A0& __a0)
                    ^
llvm-project/libcxx/include/memory:1720:21: note: previous definition is here
        static void __construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
                    ^
```

I haven't investigated further yet.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D48753/new/

https://reviews.llvm.org/D48753





More information about the cfe-commits mailing list