llvm-project/libcxx/test/std/utilities
Eric Fiselier c24e6dd3c8 [libc++] Extension: Make `move` and `forward` constexpr in C++11.
Summary:
`std::move` and `std::forward` were not marked constexpr in C++11.  This can be very damaging because it makes otherwise constant expressions non-constant. For example:

```
#include <utility>
template <class T>
struct Foo {
  constexpr Foo(T&& tx) :  t(std::move(tx)) {}
  T t;
};
[[clang::require_constant_initialization]] Foo<int> f(42); // Foo should be constant initialized but C++11 move is not constexpr. As a result `f` is an unsafe global.
```

This patch applies `constexpr` to `move` and `forward` as an extension in C++11. Normally the library is not allowed to add `constexpr` because it may be observable to the user. In particular adding constexpr may cause valid code to stop compiling. However these problems only happen in more complex situations, like making `__invoke(...)` constexpr. `forward` and `move` are simply enough that applying `constexpr` is safe. 

Note that libstdc++ has offered this extension since at least 4.8.1.

Most of the changes in this patch are simply test cleanups or additions. The main changes in the tests are:

* Fold all `forward_N.fail.cpp` tests into a single `forward.fail.cpp` test using -verify.
* Delete most `move_only_N.fail.cpp` tests because they weren't actually testing anything.
* Fold `move_copy.pass.cpp` and `move_only.pass.cpp` into a single `move.pass.cpp` test.
* Add return type and noexcept tests for `forward` and `move`.




Reviewers: rsmith, mclow.lists, EricWF

Subscribers: K-ballo, loladiro

Differential Revision: https://reviews.llvm.org/D24637

llvm-svn: 282439
2016-09-26 20:55:02 +00:00
..
allocator.adaptor Replace __cplusplus comparisons and dialect __has_feature checks with TEST_STD_VER. 2016-06-14 21:31:42 +00:00
any Improve constexpr tests for std::any 2016-09-07 02:38:48 +00:00
function.objects Add missing _v traits. is_bind_expression_v, is_placeholder_v and uses_allocator_v 2016-09-22 00:23:15 +00:00
intseq Remove trailing whitespace in test suite. Approved by Marshall Clow. 2016-06-01 21:35:39 +00:00
memory [libc++] Remove various C++03 feature test macros 2016-09-25 03:34:28 +00:00
meta Make std::is_assignable tolerate references to incomplete types. 2016-07-25 02:08:55 +00:00
ratio Move remaining _LIBCPP_VERSION tests into test/libcxx 2016-06-22 02:23:22 +00:00
template.bitset Move remaining _LIBCPP_VERSION tests into test/libcxx 2016-06-22 02:23:22 +00:00
time Prevent failures by marking Clock::is_steady tests as UNSUPPORTED: asan. 2016-07-18 02:29:33 +00:00
tuple Recommit r276548 - Make pair/tuples assignment operators SFINAE properly. 2016-07-25 02:36:42 +00:00
type.index Move remaining _LIBCPP_VERSION tests into test/libcxx 2016-06-22 02:23:22 +00:00
utilities.general
utility [libc++] Extension: Make `move` and `forward` constexpr in C++11. 2016-09-26 20:55:02 +00:00
utility.requirements
nothing_to_do.pass.cpp