1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s 2 3 // The result of the expression const_cast<T>(v) is of type T. If T is 4 // an lvalue reference to object type, the result is an lvalue; if T 5 // is an rvalue reference to object type, the result is an xvalue;. 6 7 unsigned int f(int); 8 9 template<typename T> T& lvalue(); 10 template<typename T> T&& xvalue(); 11 template<typename T> T prvalue(); 12 13 void test_classification(const int *ptr) { 14 int *ptr0 = const_cast<int *&&>(ptr); 15 int *ptr1 = const_cast<int *&&>(xvalue<const int*>()); 16 int *ptr2 = const_cast<int *&&>(prvalue<const int*>()); 17 } 18 19 struct A { 20 volatile unsigned ubf : 4; 21 volatile unsigned uv; 22 volatile int sv; 23 void foo(); 24 bool pred(); 25 }; 26 27 void test(A &a) { 28 unsigned &t0 = const_cast<unsigned&>(a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} 29 unsigned &t1 = const_cast<unsigned&>(a.foo(), a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} 30 unsigned &t2 = const_cast<unsigned&>(a.pred() ? a.ubf : a.ubf); // expected-error {{const_cast from bit-field lvalue to reference type}} 31 unsigned &t3 = const_cast<unsigned&>(a.pred() ? a.ubf : a.uv); // expected-error {{const_cast from bit-field lvalue to reference type}} 32 unsigned &t4 = const_cast<unsigned&>(a.pred() ? a.ubf : a.sv); // expected-error {{const_cast from rvalue to reference type}} 33 } 34