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