1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions -Wc++11-compat
3 void f() {
4   auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}}
5   auto *b = b; // expected-error{{variable 'b' declared with 'auto' type cannot appear in its own initializer}}
6   const auto c = c; // expected-error{{variable 'c' declared with 'auto' type cannot appear in its own initializer}}
7   if (auto d = d) {} // expected-error {{variable 'd' declared with 'auto' type cannot appear in its own initializer}}
8   auto e = ({ auto f = e; 0; }); // expected-error {{variable 'e' declared with 'auto' type cannot appear in its own initializer}}
9 }
10 
11 void g() {
12   auto a; // expected-error{{declaration of variable 'a' with type 'auto' requires an initializer}}
13 
14   auto *b; // expected-error{{declaration of variable 'b' with type 'auto *' requires an initializer}}
15 
16   if (auto b) {} // expected-error {{must have an initializer}}
17   for (;auto b;) {} // expected-error {{must have an initializer}}
18   while (auto b) {} // expected-error {{must have an initializer}}
19   if (auto b = true) { (void)b; }
20 }
21 
22 auto n(1,2,3); // expected-error{{initializer for variable 'n' with type 'auto' contains multiple expressions}}
23 
24 namespace N
25 {
26   auto a = "const char [16]", *p = &a;
27 }
28 
29 void h() {
30   auto b = 42ULL;
31 
32   for (auto c = 0; c < b; ++c) {
33   }
34 }
35 
36 template<typename T, typename U> struct same;
37 template<typename T> struct same<T, T> {};
38 
39 void p3example() {
40   auto x = 5;
41   const auto *v = &x, u = 6;
42   static auto y = 0.0;
43   // In C++98: 'auto' storage class specifier is redundant and incompatible with C++0x
44   // In C++0x: 'auto' storage class specifier is not permitted in C++0x, and will not be supported in future releases
45   auto int r; // expected-warning {{'auto' storage class specifier}}
46 
47   same<__typeof(x), int> xHasTypeInt;
48   same<__typeof(v), const int*> vHasTypeConstIntPtr;
49   same<__typeof(u), const int> uHasTypeConstInt;
50   same<__typeof(y), double> yHasTypeDouble;
51 }
52 
53 #if __cplusplus >= 201103L
54 namespace PR13293 {
55   // Ensure that dependent declarators have their deduction delayed.
56   int f(char);
57   double f(short);
58   template<typename T> struct S {
59     static constexpr auto (*p)(T) = &f;
60   };
61 
62   constexpr int (*f1)(char) = &f;
63   constexpr double (*f2)(short) = &f;
64   static_assert(S<char>::p == f1, "");
65   static_assert(S<short>::p == f2, "");
66 
67   struct K { int n; };
68   template<typename T> struct U {
69     static constexpr auto (T::*p) = &K::n;
70   };
71   static_assert(U<K>::p == &K::n, "");
72 
73   template<typename T>
74   using X = auto(int) -> auto(*)(T) -> auto(*)(char) -> long;
75   X<double> x;
76   template<typename T> struct V {
77     //static constexpr auto (*p)(int) -> auto(*)(T) -> auto(*)(char) = &x; // ill-formed
78     static constexpr auto (*(*(*p)(int))(T))(char) = &x; // ok
79   };
80   V<double> v;
81 
82   int *g(double);
83   template<typename T> void h() {
84     new (auto(*)(T)) (&g);
85   }
86   template void h<double>();
87 }
88 #endif
89 
90 auto fail((unknown)); // expected-error{{use of undeclared identifier 'unknown'}}
91 int& crash = fail;
92