p1-0x.cpp 846 B

12345678910111213141516171819
  1. // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
  2. // If T is an lvalue reference type or an rvalue reference to function
  3. // type, the result is an lvalue; if T is an rvalue reference to
  4. // object type, the result is an xvalue;
  5. unsigned int f(int);
  6. template<typename T> T&& xvalue();
  7. void test_classification(char *ptr) {
  8. int (&fr0)(int) = reinterpret_cast<int (&&)(int)>(f);
  9. int &&ir0 = reinterpret_cast<int &&>(*ptr);
  10. int &&ir1 = reinterpret_cast<int &&>(0); // expected-error {{rvalue to reference type}}
  11. int &&ir2 = reinterpret_cast<int &&>('a'); // expected-error {{rvalue to reference type}}
  12. int &&ir3 = reinterpret_cast<int &&>(xvalue<char>());
  13. // Per DR1268, reinterpret_cast can convert between lvalues and xvalues.
  14. int &ir4 = reinterpret_cast<int &>(xvalue<char>());
  15. int &&ir5 = reinterpret_cast<int &&>(*ptr);
  16. }