llvm-project/libcxx/include
Dimitry Andric 251c629117 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

llvm-svn: 245421
2015-08-19 06:43:33 +00:00
..
experimental Remove commented out TODOs. They defined unneeded methods. 2015-08-19 03:48:08 +00:00
ext Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
support cmath: account for MSVCRT 12.0 changes 2015-02-28 20:18:39 +00:00
CMakeLists.txt Add option to turn off installation of headers. 2014-12-12 22:52:58 +00:00
__bit_reference Get tests running with warnings. Fix warnings in headers and tests 2015-02-05 20:28:37 +00:00
__config Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
__debug Print log/error messages on stderr, not stdout 2015-03-10 07:57:43 +00:00
__functional_03 [libcxx] Fix PR23589: std::function doesn't recognize null pointer to varargs function. 2015-08-18 19:41:51 +00:00
__functional_base Remove almost everything in <__functional_base_03> 2015-07-22 22:23:49 +00:00
__functional_base_03 Cleanup C++03 __invoke for Bullets 3 and 4. 2015-07-28 02:15:53 +00:00
__hash_table Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
__locale Fix ctype_byname<wchar_t>::do_is() mask checking.... again 2015-03-11 17:00:28 +00:00
__mutex_base
__refstring Fix some -Wundef issues. 2015-02-05 02:34:59 +00:00
__split_buffer Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates. 2015-07-13 20:04:56 +00:00
__sso_allocator Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
__std_stream Enable and fix warnings during the build. 2015-07-18 20:40:46 +00:00
__tree Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
__tuple [libcxx] Move tuple_size and tuple_element overloads for pair and array out of !defined(_LIBCPP_HAS_NO_VARIADICS) block. 2015-03-17 15:08:03 +00:00
__undef___deallocate Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
__undef_min_max
algorithm Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
array [libcxx] Move tuple_size and tuple_element overloads for pair and array out of !defined(_LIBCPP_HAS_NO_VARIADICS) block. 2015-03-17 15:08:03 +00:00
atomic Fix PR24114 - std::atomic for non-Clang is not a literal type 2015-07-14 17:50:27 +00:00
bitset
cassert
ccomplex
cctype cctype: tweak inclusions for _LIBCPP_MSVCRT case 2015-02-13 22:15:28 +00:00
cerrno
cfenv
cfloat
chrono
cinttypes Make *abs() and *div() work on CloudABI. 2015-03-16 14:27:44 +00:00
ciso646
climits
clocale Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
cmath Provide std::abs(<floating-point>) in <cmath> on Solaris. 2015-03-18 15:24:18 +00:00
codecvt
complex
complex.h
condition_variable
csetjmp
csignal
cstdarg
cstdbool
cstddef
cstdint
cstdio Make the presence of stdin and stdout optional. 2015-03-26 14:35:46 +00:00
cstdlib Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
cstring Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
ctgmath
ctime Make support for thread-unsafe C functions optional. 2015-06-24 08:44:38 +00:00
cwchar Make the presence of stdin and stdout optional. 2015-03-26 14:35:46 +00:00
cwctype
deque Fix warnings in deque tests 2015-07-19 00:31:54 +00:00
exception [libcxx] Fix detection of __is_final. 2015-06-13 07:08:02 +00:00
forward_list Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates. 2015-07-13 20:04:56 +00:00
fstream Add option to disable access to the global filesystem namespace. 2015-03-12 15:44:39 +00:00
functional [libcxx] Fix PR23589: std::function doesn't recognize null pointer to varargs function. 2015-08-18 19:41:51 +00:00
future K-ballo pointed out that I missed one of the specializations of packaged_task when I committed r241068. Thanks for the catch. 2015-06-30 18:28:35 +00:00
initializer_list
iomanip
ios
iosfwd Revert: Revert r227804: Use fseek/ftell instead of fseeko/ftello when Newlib is the libc 2015-02-03 15:34:17 +00:00
iostream Make the presence of stdin and stdout optional. 2015-03-26 14:35:46 +00:00
istream
iterator A few bits of N2994 didn't get fully implemented a long time ago. Thanks to STL@microsoft.com for the bug report 2015-04-16 21:36:54 +00:00
limits
list Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates. 2015-07-13 20:04:56 +00:00
locale [libcxx] Disable -Wnon-virtual-dtor warning in <locale> 2015-08-18 19:39:35 +00:00
map Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
memory Broke C++03 compatibility in 245330. Fix that. 2015-08-18 19:51:37 +00:00
module.modulemap Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
mutex [libcxx] Add atomic_support.h header to src that handles needed atomic operations. 2015-07-07 00:27:16 +00:00
new [libcxx] Rework sized delete. 2015-05-19 02:03:22 +00:00
numeric
ostream Make seeking on an ostream that has eofbit set work correctly. Fixes PR#21361 2015-06-22 15:01:21 +00:00
queue Move the default template arguments into the forward declarations for the container adapters: stack and queue. References PR#22605. 2015-02-18 17:51:56 +00:00
random Remove unused typedefs in random and regex 2015-07-18 22:57:14 +00:00
ratio Fix building and testing libc++ with GCC. 2015-05-20 03:15:01 +00:00
regex Make regex and any assert when they should throw an exception _but_ the user has decreed 'no exceptions'. This matches the behavior of string and vector 2015-08-17 21:14:16 +00:00
scoped_allocator Add 'is_always_equal' tests for scoped_allocator. Found that I had typed '||' where I meant '&&' in the code; fixed that, too 2015-06-03 16:15:55 +00:00
set Fix for LWG Issue 2059: C++0x ambiguity problem with map::erase 2015-05-10 13:35:00 +00:00
shared_mutex Implement N4508: shared_mutex. Reviewed as http://reviews.llvm.org/D10480 2015-06-30 14:04:14 +00:00
sstream
stack Move the default template arguments into the forward declarations for the container adapters: stack and queue. References PR#22605. 2015-02-18 17:51:56 +00:00
stdexcept Fix unused private field warning in stdexcept after r207695. 2015-02-05 07:40:48 +00:00
streambuf Make basic_streambuf::xsputn write characters in chunks whenever possible, instead of one at a time. References PR#10193 2015-02-19 16:17:46 +00:00
string implement more of N4258 - Cleaning up noexcept in the standard library. Specifically add new noexcept stuff to vector and string's move-assignment operations 2015-08-18 18:57:00 +00:00
strstream
system_error
tgmath.h
thread Fix use of static_assert macro with nested commas 2015-08-19 03:38:41 +00:00
tuple [libcxx] Fix detection of __is_final. 2015-06-13 07:08:02 +00:00
type_traits Protect template argument from user interference. 2015-08-10 16:58:04 +00:00
typeindex
typeinfo
unordered_map Fix warnings about pessimizing return moves for C++11 and higher 2015-08-19 06:43:33 +00:00
unordered_set Implement the first part of N4258: 'Cleaning up noexcept in the Library'. This patch deals with swapping containers, and implements a more strict noexcept specification (a conforming extension) than the standard mandates. 2015-07-13 20:04:56 +00:00
utility [libcxx] Move tuple_size and tuple_element overloads for pair and array out of !defined(_LIBCPP_HAS_NO_VARIADICS) block. 2015-03-17 15:08:03 +00:00
valarray Handle function name conflicts in _LIBCPP_MSVCRT mode 2015-02-13 22:15:32 +00:00
vector implement more of N4258 - Cleaning up noexcept in the standard library. Specifically add new noexcept stuff to vector and string's move-assignment operations 2015-08-18 18:57:00 +00:00