Author: dim Date: Wed Aug 19 01:43:33 2015 New Revision: 245421 URL: http://llvm.org/viewvc/llvm-project?rev=245421&view=rev Log: Fix warnings about pessimizing return moves for C++11 and higher
Summary: Throughout the libc++ headers, there are a few instances where _VSTD::move() is used to return a local variable. Howard commented in r189039 that these were there "for non-obvious reasons such as to help things limp along in C++03 language mode". However, when compiling these headers with warnings on, and in C++11 or higher mode (like we do in FreeBSD), they cause the following complaints about pessimizing moves: In file included from tests.cpp:26: In file included from tests.hpp:29: /usr/include/c++/v1/map:1368:12: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move] return _VSTD::move(__h); // explicitly moved for C++03 ^ /usr/include/c++/v1/__config:368:15: note: expanded from macro '_VSTD' #define _VSTD std::_LIBCPP_NAMESPACE ^ Attempt to fix this by adding a _LIBCPP_EXPLICIT_MOVE() macro to __config, which gets defined to _VSTD::move for pre-C++11, and to nothing for C++11 and later. I am not completely satisfied with the macro name (I also considered _LIBCPP_COMPAT_MOVE and some other variants), so suggestions are welcome. :) Reviewers: mclow.lists, howard.hinnant, EricWF Subscribers: arthur.j.odwyer, cfe-commits Differential Revision: http://reviews.llvm.org/D11394 Modified: libcxx/trunk/include/__config libcxx/trunk/include/__hash_table libcxx/trunk/include/__tree libcxx/trunk/include/algorithm libcxx/trunk/include/ext/hash_map libcxx/trunk/include/map libcxx/trunk/include/unordered_map Modified: libcxx/trunk/include/__config URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/__config (original) +++ libcxx/trunk/include/__config Wed Aug 19 01:43:33 2015 @@ -716,6 +716,12 @@ template <unsigned> struct __static_asse #define _LIBCPP_CONSTEXPR_AFTER_CXX11 #endif +#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES +# define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x) +#else +# define _LIBCPP_EXPLICIT_MOVE(x) (x) +#endif + #ifndef _LIBCPP_HAS_NO_ASAN extern "C" void __sanitizer_annotate_contiguous_container( const void *, const void *, const void *, const void *); Modified: libcxx/trunk/include/__hash_table URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__hash_table?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/__hash_table (original) +++ libcxx/trunk/include/__hash_table Wed Aug 19 01:43:33 2015 @@ -2108,7 +2108,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc> __h.get_deleter().__value_constructed = true; __h->__hash_ = hash_function()(__h->__value_); __h->__next_ = nullptr; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -2124,7 +2124,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc> __h.get_deleter().__value_constructed = true; __h->__hash_ = __hash; __h->__next_ = nullptr; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template <class _Tp, class _Hash, class _Equal, class _Alloc> Modified: libcxx/trunk/include/__tree URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__tree?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/__tree (original) +++ libcxx/trunk/include/__tree Wed Aug 19 01:43:33 2015 @@ -1843,7 +1843,7 @@ __tree<_Tp, _Compare, _Allocator>::__con __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v); __h.get_deleter().__value_constructed = true; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES Modified: libcxx/trunk/include/algorithm URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/algorithm (original) +++ libcxx/trunk/include/algorithm Wed Aug 19 01:43:33 2015 @@ -851,7 +851,7 @@ for_each(_InputIterator __first, _InputI { for (; __first != __last; ++__first) __f(*__first); - return _VSTD::move(__f); // explicitly moved for (emulated) C++03 + return _LIBCPP_EXPLICIT_MOVE(__f); // explicitly moved for (emulated) C++03 } // find Modified: libcxx/trunk/include/ext/hash_map URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/ext/hash_map?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/ext/hash_map (original) +++ libcxx/trunk/include/ext/hash_map Wed Aug 19 01:43:33 2015 @@ -681,7 +681,7 @@ hash_map<_Key, _Tp, _Hash, _Pred, _Alloc __h.get_deleter().__first_constructed = true; __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); __h.get_deleter().__second_constructed = true; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> Modified: libcxx/trunk/include/map URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/map?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/map (original) +++ libcxx/trunk/include/map Wed Aug 19 01:43:33 2015 @@ -1523,7 +1523,7 @@ map<_Key, _Tp, _Compare, _Allocator>::__ __h.get_deleter().__first_constructed = true; __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template <class _Key, class _Tp, class _Compare, class _Allocator> Modified: libcxx/trunk/include/unordered_map URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/unordered_map?rev=245421&r1=245420&r2=245421&view=diff ============================================================================== --- libcxx/trunk/include/unordered_map (original) +++ libcxx/trunk/include/unordered_map Wed Aug 19 01:43:33 2015 @@ -1511,7 +1511,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _ __h.get_deleter().__first_constructed = true; __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits