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