p3.cpp revision c2c11446caaee2d5a787cc8d0310330c6364210d
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wc++11-compat 2// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions -Wc++11-compat 3void 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 11void 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 {{expected '='}} 17 for (;auto b;) {} // expected-error {{expected '='}} 18 while (auto b) {} // expected-error {{expected '='}} 19 if (auto b = true) { (void)b; } 20} 21 22auto n(1,2,3); // expected-error{{initializer for variable 'n' with type 'auto' contains multiple expressions}} 23 24namespace N 25{ 26 auto a = "const char [16]", *p = &a; 27} 28 29void h() { 30 auto b = 42ULL; 31 32 for (auto c = 0; c < b; ++c) { 33 } 34} 35 36template<typename T, typename U> struct same; 37template<typename T> struct same<T, T> {}; 38 39void 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