]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
Vendor import of clang trunk r126547:
[FreeBSD/FreeBSD.git] / test / CXX / dcl.dcl / dcl.spec / dcl.type / dcl.spec.auto / p3.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
2 void f() {
3   auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}}
4   auto *b = b; // expected-error{{variable 'b' declared with 'auto' type cannot appear in its own initializer}}
5   const auto c = c; // expected-error{{variable 'c' declared with 'auto' type cannot appear in its own initializer}}
6   if (auto d = d) {} // expected-error {{variable 'd' declared with 'auto' type cannot appear in its own initializer}}
7   auto e = ({ auto f = e; 0; }); // expected-error {{variable 'e' declared with 'auto' type cannot appear in its own initializer}}
8 }
9
10 void g() {
11   auto a; // expected-error{{declaration of variable 'a' with type 'auto' requires an initializer}}
12   
13   auto *b; // expected-error{{declaration of variable 'b' with type 'auto *' requires an initializer}}
14
15   if (auto b) {} // expected-error {{expected '='}}
16   for (;auto b;) {} // expected-error {{expected '='}}
17   while (auto b) {} // expected-error {{expected '='}}
18   if (auto b = true) { (void)b; }
19 }
20
21 auto n(1,2,3); // expected-error{{initializer for variable 'n' with type 'auto' contains multiple expressions}}
22
23 namespace N
24 {
25   auto a = "const char [16]", *p = &a;
26 }
27
28 void h() {
29   auto b = 42ULL;
30
31   for (auto c = 0; c < b; ++c) {
32   }
33 }
34
35 template<typename T, typename U> struct same;
36 template<typename T> struct same<T, T> {};
37
38 void p3example() {
39   auto x = 5;
40   const auto *v = &x, u = 6;
41   static auto y = 0.0;
42   auto int r; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}}
43
44   same<decltype(x), int> xHasTypeInt;
45   same<decltype(v), const int*> vHasTypeConstIntPtr;
46   same<decltype(u), const int> uHasTypeConstInt;
47   same<decltype(y), double> yHasTypeDouble;
48 }