llvm-project/libcxx/test/std
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
..
algorithms Implement C++17 std::sample. 2016-08-28 22:14:37 +00:00
atomics libc++: name anonymous structs 2016-07-12 20:14:52 +00:00
containers Update -verify test to use new static assert message 2016-09-25 08:30:05 +00:00
depr Fix unreferenced parameter warning. Patch from STL@microsoft.com 2016-06-30 04:22:58 +00:00
diagnostics Fix incorrect include in is_error_code_enum.pass.cpp 2016-09-24 18:16:53 +00:00
experimental Avoid compile error by giving the test type a user defined default constructor 2016-09-07 03:50:36 +00:00
input.output Implement is_error_code_v and is_error_condition_v for c++17. Rework the tests for is_error_code and is_error_condition, since they were really lacking. Thanks to Alisdair for the heads-up that we were missing these. 2016-09-24 17:36:14 +00:00
iterators [libcxx] Add missing c++98 xfail. NFC. 2016-09-16 14:32:19 +00:00
language.support Avoid applying unary minus to unsigned integers. Patch from STL@microsoft.com 2016-06-30 04:21:52 +00:00
localization Apply curr_symbol.pass.cpp test fix to missed test case 2016-09-04 04:09:25 +00:00
numerics Remove test for the sign of a NaN - doesn't work on MIPS, not strictly legal. Fixes bug 28936 2016-08-11 18:46:24 +00:00
re [libcxx] Add "flag" default arg: basic_regex ptr_size_flag ctor 2016-08-07 22:26:04 +00:00
strings Fix a few static_asserts that need extra parens on -03 2016-09-24 23:52:21 +00:00
thread Implement is_error_code_v and is_error_condition_v for c++17. Rework the tests for is_error_code and is_error_condition, since they were really lacking. Thanks to Alisdair for the heads-up that we were missing these. 2016-09-24 17:36:14 +00:00
utilities [libc++] Extension: Make `move` and `forward` constexpr in C++11. 2016-09-26 20:55:02 +00:00
nothing_to_do.pass.cpp