Home | History | Annotate | Download | only in forward
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // test forward
     11 
     12 #include <utility>
     13 #include <cassert>
     14 
     15 #include "test_macros.h"
     16 
     17 struct A
     18 {
     19 };
     20 
     21 A source() {return A();}
     22 const A csource() {return A();}
     23 
     24 typedef char one;
     25 struct two {one _[2];};
     26 struct four {one _[4];};
     27 struct eight {one _[8];};
     28 
     29 one test(A&);
     30 two test(const A&);
     31 
     32 int main()
     33 {
     34     A a;
     35     const A ca = A();
     36 
     37     ((void)a); // Prevent unused warning
     38     ((void)ca); // Prevent unused warning
     39 
     40 #if TEST_STD_VER < 11
     41     static_assert(sizeof(test(std::forward<A&>(a))) == 1, "");
     42     static_assert(sizeof(test(std::forward<A>(a))) == 1, "");
     43 
     44     // Libc++'s C++03 implementation of 'forward' cannot accept true non-const
     45     // rvalues.
     46     // static_assert(sizeof(test(std::forward<A>(source()))) == 2, "");
     47 
     48     static_assert(sizeof(test(std::forward<const A&>(a))) == 2, "");
     49     static_assert(sizeof(test(std::forward<const A&>(source()))) == 2, "");
     50     static_assert(sizeof(test(std::forward<const A>(a))) == 2, "");
     51     static_assert(sizeof(test(std::forward<const A>(source()))) == 2, "");
     52 
     53     static_assert(sizeof(test(std::forward<const A&>(ca))) == 2, "");
     54     static_assert(sizeof(test(std::forward<const A&>(csource()))) == 2, "");
     55     static_assert(sizeof(test(std::forward<const A>(ca))) == 2, "");
     56     static_assert(sizeof(test(std::forward<const A>(csource()))) == 2, "");
     57 #endif
     58 }
     59