On 22/09/16 01:49 -0700, Tim Shen wrote:
Done. When writing the initial version, I was trying to save as much
qualifications as possible (as long as the semantic doesn't change)
for readability, but that might not be a good idea.
It does change the semantics, as forward<_Tp>(__tp) can find another
function via ADL (see the new test in this patch).
Tested powerpc64le-linux, committed to trunk.
commit fe8a92068c783bd2a911c1864c62ffd8c3f31ea1
Author: Jonathan Wakely
Date: Thu Sep 22 10:45:50 2016 +0100
Always qualify std::forward in
* include/bits/uses_allocator.h (__uses_allocator_construct): Qualify
std::forward and ::new. Cast pointer to void*.
* include/std/variant (_Variant_storage, _Union, _Variant_base)
(__access, __visit_invoke, variant, visit): Qualify std::forward.
* testsuite/20_util/variant/compile.cc: Test for ADL problems.
diff --git a/libstdc++-v3/include/bits/uses_allocator.h b/libstdc++-v3/include/bits/uses_allocator.h
index 500bd90..c7d14f3 100644
--- a/libstdc++-v3/include/bits/uses_allocator.h
+++ b/libstdc++-v3/include/bits/uses_allocator.h
@@ -144,24 +144,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template
void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
_Args&&... __args)
-{ new (__ptr) _Tp(forward<_Args>(__args)...); }
+{ ::new ((void*)__ptr) _Tp(std::forward<_Args>(__args)...); }
template
void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
_Args&&... __args)
-{ new (__ptr) _Tp(allocator_arg, *__a._M_a, forward<_Args>(__args)...); }
+{
+ ::new ((void*)__ptr) _Tp(allocator_arg, *__a._M_a,
+ std::forward<_Args>(__args)...);
+}
template
void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
_Args&&... __args)
-{ new (__ptr) _Tp(forward<_Args>(__args)..., *__a._M_a); }
+{ ::new ((void*)__ptr) _Tp(std::forward<_Args>(__args)..., *__a._M_a); }
template
void __uses_allocator_construct(const _Alloc& __a, _Tp* __ptr,
_Args&&... __args)
{
__uses_allocator_construct_impl(__use_alloc<_Tp, _Alloc, _Args...>(__a),
- __ptr, forward<_Args>(__args)...);
+ __ptr, std::forward<_Args>(__args)...);
}
_GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 1ad33fc..ac483f3 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -298,7 +298,7 @@ namespace __variant
template
constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args)
- : _M_union(in_place<_Np>, forward<_Args>(__args)...)
+ : _M_union(in_place<_Np>, std::forward<_Args>(__args)...)
{ }
~_Variant_storage() = default;
@@ -316,13 +316,13 @@ namespace __variant
template
constexpr _Union(in_place_index_t<0>, _Args&&... __args)
- : _M_first(in_place<0>, forward<_Args>(__args)...)
+ : _M_first(in_place<0>, std::forward<_Args>(__args)...)
{ }
template>
constexpr _Union(in_place_index_t<_Np>, _Args&&... __args)
- : _M_rest(in_place<_Np - 1>, forward<_Args>(__args)...)
+ : _M_rest(in_place<_Np - 1>, std::forward<_Args>(__args)...)
{ }
_Uninitialized<__storage<_First>> _M_first;
@@ -386,7 +386,7 @@ namespace __variant
template
constexpr explicit
_Variant_base(in_place_index_t<_Np> __i, _Args&&... __args)
- : _Storage(__i, forward<_Args>(__args)...), _M_index(_Np)
+ : _Storage(__i, std::forward<_Args>(__args)...), _M_index(_Np)
{ }
template
@@ -426,7 +426,7 @@ namespace __variant
using _Storage =
__storage>>;
__uses_allocator_construct(__a, static_cast<_Storage*>(_M_storage()),
- forward<_Args>(__args)...);
+ std::forward<_Args>(__args)...);
__glibcxx_assert(_M_index == _Np);
}
@@ -581,7 +581,7 @@ namespace __variant
decltype(auto) __access(_Variant&& __v)
{
return __get_alternative<__reserved_type_map<_Variant&&, __storage<_Tp>>>(
- __get_storage(forward<_Variant>(__v)));
+ __get_storage(std::forward<_Variant>(__v)));
}
// A helper used to create variadic number of _To types.
@@ -591,10 +591,11 @@ namespace __variant
// Call the actual visitor.
// _Args are qualified storage types.
template
-decltype(auto) __visit_invoke(_Visitor&& __visitor,
- _To_type<_Args, void*>... __ptrs)
+decltype(auto)
+__visit_invoke(_Visitor&& __visitor, _To_type<_Args, void*>... __ptrs)
{
- return forward<_Visitor>(__visitor)(__get_alternative<_Args>(__ptrs)...);
+ return std::forward<_Visitor>(__visitor)(
+ __get_alternative<_Args>(__ptrs)...);
}
// Used for storing multi-dimensional vtable.
@@ -1010,7 +1011,7 @@ namespace __variant
constexpr
variant(_Tp&& __t)
noexcept(is_nothrow_constructible_v<__accepted_type<_Tp&&>, _Tp&&>)
- : variant(in_place<__accepted_index<_Tp&&>>, forward<_Tp>(__t))
+ : variant(in_place<__accepted_i