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; deduced return types are a C++14 extension}} 21decltype(auto) g2(); // expected-warning{{extension}} expected-error-re{{{{^}}deduced return types are a C++14 extension}} 22auto badness = g2(); 23 24int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}} 25 26int i(); 27auto i() -> int; 28int i() {} 29 30using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}} 31using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}} 32 33using U = auto (int) -> auto (*)(char) -> void; 34using U = void (*(int))(char); // ok 35 36int x; 37 38template <class T> 39auto i(T x) -> decltype(x) 40{ 41 return x; 42} 43 44only<double> p1 = i(1.0); 45 46template <class T> 47struct X 48{ 49 auto f(T x) -> T { return x; } 50 51 template <class U> 52 auto g(T x, U y) -> decltype(x + y) 53 { 54 return x + y; 55 } 56 57 template<typename U> 58 struct nested { 59 template <class V> 60 auto h(T x, U y, V z) -> decltype(x + y + z) 61 { 62 return x + y + z; 63 } 64 }; 65 66 template<typename U> 67 nested<U> get_nested(); 68}; 69 70X<int> xx; 71only<int> p2 = xx.f(0L); 72only<double> p3 = xx.g(0L, 1.0); 73only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f); 74 75namespace PR12053 { 76 template <typename T> 77 auto f1(T t) -> decltype(f1(t)) {} // expected-note{{candidate template ignored}} 78 79 void test_f1() { 80 f1(0); // expected-error{{no matching function for call to 'f1'}} 81 } 82 83 template <typename T> 84 auto f2(T t) -> decltype(f2(&t)) {} // expected-note{{candidate template ignored}} 85 86 void test_f2() { 87 f2(0); // expected-error{{no matching function for call to 'f2'}} 88 } 89} 90 91namespace DR1608 { 92 struct S { 93 void operator+(); 94 int operator[](int); 95 auto f() -> decltype(+*this); // expected-note {{here}} 96 auto f() -> decltype((*this)[0]); // expected-error {{cannot be overloaded}} 97 }; 98} 99 100namespace PR16273 { 101 struct A { 102 template <int N> void f(); 103 auto g()->decltype(this->f<0>()); 104 }; 105} 106 107