1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y -DCXX1Y 2// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions 3 4// FIXME: This is in p11 (?) in C++1y. 5void f() { 6 decltype(auto) a = a; // expected-error{{variable 'a' declared with 'decltype(auto)' type cannot appear in its own initializer}} 7 if (decltype(auto) b = b) {} // expected-error {{variable 'b' declared with 'decltype(auto)' type cannot appear in its own initializer}} 8 decltype(auto) c = ({ decltype(auto) d = c; 0; }); // expected-error {{variable 'c' declared with 'decltype(auto)' type cannot appear in its own initializer}} 9} 10 11void g() { 12 decltype(auto) a; // expected-error{{declaration of variable 'a' with type 'decltype(auto)' requires an initializer}} 13 14 decltype(auto) *b; // expected-error{{cannot form pointer to 'decltype(auto)'}} expected-error{{declaration of variable 'b' with type 'decltype(auto) *' requires an initializer}} 15 16 if (decltype(auto) b) {} // expected-error {{must have an initializer}} 17 for (;decltype(auto) b;) {} // expected-error {{must have an initializer}} 18 while (decltype(auto) b) {} // expected-error {{must have an initializer}} 19 if (decltype(auto) b = true) { (void)b; } 20} 21 22decltype(auto) n(1,2,3); // expected-error{{initializer for variable 'n' with type 'decltype(auto)' contains multiple expressions}} 23 24namespace N 25{ 26 // All of these are references, because a string literal is an lvalue. 27 decltype(auto) a = "const char (&)[19]", b = a, c = (a); 28} 29 30void h() { 31 decltype(auto) b = 42ULL; 32 33 for (decltype(auto) c = 0; c < b; ++c) { 34 } 35} 36 37template<typename T, typename U> struct same; 38template<typename T> struct same<T, T> {}; 39 40void i() { 41 decltype(auto) x = 5; 42 decltype(auto) int r; // expected-error {{cannot combine with previous 'decltype(auto)' declaration specifier}} expected-error {{requires an initializer}} 43} 44 45namespace p3_example { 46 template<typename T, typename U> struct is_same_impl { 47 static const bool value = false; 48 }; 49 template<typename T> struct is_same_impl<T, T> { 50 static const bool value = true; 51 }; 52 template<typename T, typename U> constexpr bool is_same() { 53 return is_same_impl<T,U>::value; 54 } 55 56 auto x = 5; 57 const auto *v = &x, u = 6; 58 static auto y = 0.0; 59 auto int r; // expected-warning {{storage class}} expected-error {{file-scope}} 60 61 static_assert(is_same<decltype(x), int>(), ""); 62 static_assert(is_same<decltype(v), const int*>(), ""); 63 static_assert(is_same<decltype(u), const int>(), ""); 64 static_assert(is_same<decltype(y), double>(), ""); 65 66#ifdef CXX1Y 67 auto f() -> int; 68 auto g() { return 0.0; } 69 auto h(); 70 71 static_assert(is_same<decltype(f), int()>(), ""); 72 static_assert(is_same<decltype(g), double()>(), ""); 73#endif 74} 75