brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 5c48ed2 Raw
33 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only %s -std=c++98 -verify2// expected-no-diagnostics3 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 these6// functions in C++98 mode, libc++ 3.1 has a "fake rvalue reference" type, and7// std::move will return by value when given an instance of that type.8 9namespace 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 22struct A {};23void 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}33