| 1 |
// RUN: %clang_cc1 -fsyntax-only %s -std=c++98 -verify |
| 2 |
// expected-no-diagnostics |
| 3 |
|
| 4 |
// This is a test for a hack in Clang that works around an issue with libc++ |
| 5 |
// 3.1's std::move and std::forward implementation. When emulating these |
| 6 |
// functions in C++98 mode, libc++ 3.1 has a "fake rvalue reference" type, and |
| 7 |
// std::move will return by value when given an instance of that type. |
| 8 |
|
| 9 |
namespace std { |
| 10 |
struct rv {}; |
| 11 |
|
| 12 |
template<bool B, typename T> struct enable_if; |
| 13 |
template<typename T> struct enable_if<true, T> { typedef T type; }; |
| 14 |
|
| 15 |
template<typename T> typename enable_if<__is_convertible(T, rv), T>::type move(T &); |
| 16 |
template<typename T> typename enable_if<!__is_convertible(T, rv), T&>::type move(T &); |
| 17 |
|
| 18 |
template<typename U, typename T> typename enable_if<__is_convertible(T, rv), U>::type forward(T &); |
| 19 |
template<typename U, typename T> typename enable_if<!__is_convertible(T, rv), U&>::type forward(T &); |
| 20 |
} |
| 21 |
|
| 22 |
struct A {}; |
| 23 |
void f(A a, std::rv rv) { |
| 24 |
a = std::move(a); |
| 25 |
rv = std::move(rv); |
| 26 |
|
| 27 |
a = std::forward<A>(a); |
| 28 |
rv = std::forward<std::rv>(rv); |
| 29 |
|
| 30 |
a = std::forward<A&>(a); |
| 31 |
rv = std::forward<std::rv&>(rv); |
| 32 |
} |