1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
22c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
32c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregortemplate<typename T> T &lvalue();
42c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregortemplate<typename T> T &&xvalue();
52c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregortemplate<typename T> T prvalue();
62c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
72c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorstruct X0 {
82c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &f() &;
92c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &f() &&;
102c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
112c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  template<typename T> int &ft(T) &;
122c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  template<typename T> float &ft(T) &&;
132c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
142c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  typedef int &(*func_int_ref)();
152c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  typedef float &(*func_float_ref)();
162c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
172c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  operator func_int_ref() &;
182c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  operator func_float_ref() &&;
192c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
202c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  void g();
212c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
222c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &operator+(const X0&) &;
232c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &operator+(const X0&) &&;
242c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
252c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  template<typename T> int &operator+(const T&) &;
262c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  template<typename T> float &operator+(const T&) &&;
272c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
282c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &h() const&;
292c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &h() &&;
30fcab48b626b7ce43625958e857061d721a43a5bcDouglas Gregor  int &h2() const&;
31fcab48b626b7ce43625958e857061d721a43a5bcDouglas Gregor  float &h2() const&&;
322c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor};
332c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
342c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorvoid X0::g() {
352c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir1 = f();
362c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir2 = X0::f();
372c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor}
382c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
392c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorvoid test_ref_qualifier_binding() {
402c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir1 = lvalue<X0>().f();
412c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr1 = xvalue<X0>().f();
422c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr2 = prvalue<X0>().f();
432c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir2 = lvalue<X0>().ft(1);
442c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr3 = xvalue<X0>().ft(2);
452c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr4 = prvalue<X0>().ft(3);
462c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor}
472c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
482c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorvoid test_ref_qualifier_binding_with_surrogates() {
492c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir1 = lvalue<X0>()();
502c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr1 = xvalue<X0>()();
512c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr2 = prvalue<X0>()();
522c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor}
532c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
542c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorvoid test_ref_qualifier_binding_operators() {
552c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir1 = lvalue<X0>() + prvalue<X0>();
562c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr1 = xvalue<X0>() + prvalue<X0>();
572c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr2 = prvalue<X0>() + prvalue<X0>();
582c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir2 = lvalue<X0>() + 1;
592c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr3 = xvalue<X0>() + 2;
602c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr4 = prvalue<X0>() + 3;
612c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor}
622c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor
632c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregorvoid test_ref_qualifier_overloading() {
642c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  int &ir1 = lvalue<X0>().h();
652c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr1 = xvalue<X0>().h();
662c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor  float &fr2 = prvalue<X0>().h();
67fcab48b626b7ce43625958e857061d721a43a5bcDouglas Gregor  int &ir2 = lvalue<X0>().h2();
68fcab48b626b7ce43625958e857061d721a43a5bcDouglas Gregor  float &fr3 = xvalue<X0>().h2();
69fcab48b626b7ce43625958e857061d721a43a5bcDouglas Gregor  float &fr4 = prvalue<X0>().h2();
702c9a03f3b249e4d9d76eadf758a33142adc4d0a4Douglas Gregor}
71