1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 2 3template <class T> 4struct only 5{ 6 only(T) {} 7 8 template <class U> 9 only(U) 10 { 11 static_assert(sizeof(U) == 0, "expected type failure"); 12 } 13}; 14 15auto f() -> int 16{ 17 return 0; 18} 19 20auto g(); // expected-error{{return without trailing return type}} 21 22int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}} 23 24int i(); 25auto i() -> int; 26int i() {} 27 28using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}} 29using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}} 30 31using U = auto (int) -> auto (*)(char) -> void; 32using U = void (*(int))(char); // ok 33 34int x; 35 36template <class T> 37auto i(T x) -> decltype(x) 38{ 39 return x; 40} 41 42only<double> p1 = i(1.0); 43 44template <class T> 45struct X 46{ 47 auto f(T x) -> T { return x; } 48 49 template <class U> 50 auto g(T x, U y) -> decltype(x + y) 51 { 52 return x + y; 53 } 54 55 template<typename U> 56 struct nested { 57 template <class V> 58 auto h(T x, U y, V z) -> decltype(x + y + z) 59 { 60 return x + y + z; 61 } 62 }; 63 64 template<typename U> 65 nested<U> get_nested(); 66}; 67 68X<int> xx; 69only<int> p2 = xx.f(0L); 70only<double> p3 = xx.g(0L, 1.0); 71only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f); 72 73namespace PR12053 { 74 template <typename T> 75 auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}} 76 77 void test_f1() { 78 f1(0); // expected-error{{no matching function for call to 'f1'}} 79 } 80 81 template <typename T> 82 auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}} 83 84 void test_f2() { 85 f2(0); // expected-error{{no matching function for call to 'f2'}} 86 } 87} 88 89namespace DR1608 { 90 struct S { 91 void operator+(); 92 int operator[](int); 93 auto f() -> decltype(+*this); // expected-note {{here}} 94 auto f() -> decltype((*this)[0]); // expected-error {{cannot be overloaded}} 95 }; 96} 97 98namespace PR16273 { 99 struct A { 100 template <int N> void f(); 101 auto g()->decltype(this->f<0>()); 102 }; 103} 104 105