1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y 2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions 3 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions 4 5 template<typename T> 6 struct only { 7 only(T); 8 template<typename U> only(U) = delete; 9 }; 10 11 void f() { 12 if (auto a = true) { 13 } 14 15 switch (auto a = 0) { 16 } 17 18 while (auto a = false) { 19 } 20 21 for (; auto a = false; ) { 22 } 23 24 new const auto (0); 25 new (auto) (0.0); 26 27 int arr[] = {1, 2, 3}; 28 for (auto i : arr) { 29 } 30 } 31 32 class X { 33 static const auto n = 'x'; 34 35 auto m = 0; // expected-error {{'auto' not allowed in non-static class member}} 36 }; 37 38 struct S { 39 static const auto a; // expected-error {{declaration of variable 'a' with type 'const auto' requires an initializer}} 40 static const auto b = 0; 41 static const int c; 42 }; 43 const int S::b; 44 const auto S::c = 0; 45 46 namespace std { template<typename T> struct initializer_list { initializer_list(); }; } 47 48 // In an initializer of the form ( expression-list ), the expression-list 49 // shall be a single assigment-expression. 50 auto parens1(1); 51 auto parens2(2, 3); // expected-error {{initializer for variable 'parens2' with type 'auto' contains multiple expressions}} 52 #if __cplusplus >= 201103L 53 auto parens3({4, 5, 6}); // expected-error {{cannot deduce type for variable 'parens3' with type 'auto' from parenthesized initializer list}} 54 auto parens4 = [p4(1)] {}; 55 auto parens5 = [p5(2, 3)] {}; // expected-error {{initializer for lambda capture 'p5' contains multiple expressions}} 56 auto parens6 = [p6({4, 5, 6})] {}; // expected-error {{cannot deduce type for lambda capture 'p6' from parenthesized initializer list}} 57 #endif 58 59 #if __cplusplus >= 201402L 60 namespace std_example { 61 // The other half of this example is in p3.cpp 62 auto f() -> int; 63 auto g() { return 0.0; } 64 auto h(); 65 } 66 #endif 67