Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 2 | |
| 3 | template <class T> |
| 4 | struct 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 | |
| 15 | auto f() -> int |
| 16 | { |
| 17 | return 0; |
| 18 | } |
| 19 | |
| 20 | auto g(); // expected-error{{return without trailing return type}} |
| 21 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 22 | int h() -> int; // expected-error{{trailing return type must specify return type 'auto', not 'int'}} |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 23 | |
Richard Smith | eefb3d5 | 2012-02-10 09:58:53 +0000 | [diff] [blame] | 24 | int i(); |
| 25 | auto i() -> int; |
| 26 | int i() {} |
| 27 | |
| 28 | using T = auto (int) -> auto (*)(char) -> void; // expected-note {{previous}} |
| 29 | using T = void; // expected-error {{type alias redefinition with different types ('void' vs 'auto (int) -> auto (*)(char) -> void')}} |
| 30 | |
| 31 | using U = auto (int) -> auto (*)(char) -> void; |
| 32 | using U = void (*(int))(char); // ok |
| 33 | |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 34 | int x; |
| 35 | |
| 36 | template <class T> |
| 37 | auto i(T x) -> decltype(x) |
| 38 | { |
| 39 | return x; |
| 40 | } |
| 41 | |
| 42 | only<double> p1 = i(1.0); |
| 43 | |
| 44 | template <class T> |
| 45 | struct 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 | |
| 68 | X<int> xx; |
| 69 | only<int> p2 = xx.f(0L); |
| 70 | only<double> p3 = xx.g(0L, 1.0); |
| 71 | only<double> p4 = xx.get_nested<double>().h(0L, 1.0, 3.14f); |