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