1 // RUN: %clang_cc1 -verify -std=c++1y %s 2 3 namespace std { 4 template<typename T> struct initializer_list { 5 const T *p; 6 unsigned long n; 7 initializer_list(const T *p, unsigned long n); 8 }; 9 } 10 11 int i; 12 int &&f(); 13 14 using Int = int; 15 using IntLRef = int&; 16 using IntRRef = int&&; 17 using InitListInt = std::initializer_list<int>; 18 using IntPtr = int*; 19 20 auto x3a = i; 21 decltype(auto) x3d = i; 22 using Int = decltype(x3a); 23 using Int = decltype(x3d); 24 25 auto x4a = (i); 26 decltype(auto) x4d = (i); 27 using Int = decltype(x4a); 28 using IntLRef = decltype(x4d); 29 30 auto x5a = f(); 31 decltype(auto) x5d = f(); 32 using Int = decltype(x5a); 33 using IntRRef = decltype(x5d); 34 35 auto x6a = { 1, 2 }; 36 decltype(auto) x6d = { 1, 2 }; // expected-error {{cannot deduce 'decltype(auto)' from initializer list}} 37 using InitListInt = decltype(x6a); 38 39 auto *x7a = &i; 40 decltype(auto) *x7d = &i; // expected-error {{cannot form pointer to 'decltype(auto)'}} 41 using IntPtr = decltype(x7a); 42 43 struct S {}; 44 45 decltype(auto) f1(); 46 decltype(auto) (*f2)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}} 47 decltype(auto) *f3(); // expected-error {{cannot form pointer to 'decltype(auto)'}} 48 const decltype(auto) f4(); // expected-error {{'decltype(auto)' cannot be combined with other type specifiers}} 49 typedef decltype(auto) f5(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} 50 decltype(auto) ((((((f6))))())); // ok 51 decltype(auto) f7()(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{function cannot return function type}} 52 decltype(auto) (S::*f8)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}} 53 decltype(auto) &f9(); // expected-error {{cannot form reference to 'decltype(auto)'}} 54 decltype(auto) (&f10())[10]; // expected-error {{cannot form array of 'decltype(auto)'}} 55 56 decltype(auto) ((((((v1)))))) = 0; // ok 57 decltype(auto) v2[1] = { 0 }; // expected-error {{cannot form array of 'decltype(auto)'}} 58 decltype(auto) &v3 = { 0 }; // expected-error {{cannot form reference to 'decltype(auto)'}} 59 decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}} 60 61 auto multi1a = 0, &multi1b = multi1a; 62 auto multi1c = multi1a, multi1d = multi1b; 63 decltype(auto) multi1e = multi1a, multi1f = multi1b; // expected-error {{'decltype(auto)' deduced as 'int' in declaration of 'multi1e' and deduced as 'int &' in declaration of 'multi1f'}} 64 65 auto f1a() { return 0; } 66 decltype(auto) f1d() { return 0; } 67 using Int = decltype(f1a()); 68 using Int = decltype(f1d()); 69 70 auto f2a(int n) { return n; } 71 decltype(auto) f2d(int n) { return n; } 72 using Int = decltype(f2a(0)); 73 using Int = decltype(f2d(0)); 74 75 auto f3a(int n) { return (n); } 76 decltype(auto) f3d(int n) { return (n); } // expected-warning {{reference to stack memory}} 77 using Int = decltype(f3a(0)); 78 using IntLRef = decltype(f3d(0)); 79 80 auto f4a(int n) { return f(); } 81 decltype(auto) f4d(int n) { return f(); } 82 using Int = decltype(f4a(0)); 83 using IntRRef = decltype(f4d(0)); 84 85 auto f5aa(int n) { auto x = f(); return x; } 86 auto f5ad(int n) { decltype(auto) x = f(); return x; } 87 decltype(auto) f5da(int n) { auto x = f(); return x; } 88 decltype(auto) f5dd(int n) { decltype(auto) x = f(); return x; } // expected-error {{rvalue reference to type 'int' cannot bind to lvalue}} 89 using Int = decltype(f5aa(0)); 90 using Int = decltype(f5ad(0)); 91 using Int = decltype(f5da(0)); 92 93 auto init_list_1() { return { 1, 2, 3 }; } // expected-error {{cannot deduce return type from initializer list}} 94 decltype(auto) init_list_2() { return { 1, 2, 3 }; } // expected-error {{cannot deduce return type from initializer list}} 95