1651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y
2651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions
35f31f0893d75203c326ddcd9808099bbfe34aec0David Blaikie// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions
434b41d939a1328f484511c6002ba2456db879a29Richard Smith
534b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename T>
634b41d939a1328f484511c6002ba2456db879a29Richard Smithstruct only {
734b41d939a1328f484511c6002ba2456db879a29Richard Smith  only(T);
834b41d939a1328f484511c6002ba2456db879a29Richard Smith  template<typename U> only(U) = delete;
934b41d939a1328f484511c6002ba2456db879a29Richard Smith};
1034b41d939a1328f484511c6002ba2456db879a29Richard Smith
1134b41d939a1328f484511c6002ba2456db879a29Richard Smithvoid f() {
1234b41d939a1328f484511c6002ba2456db879a29Richard Smith  if (auto a = true) {
1334b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
1434b41d939a1328f484511c6002ba2456db879a29Richard Smith
1534b41d939a1328f484511c6002ba2456db879a29Richard Smith  switch (auto a = 0) {
1634b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
1734b41d939a1328f484511c6002ba2456db879a29Richard Smith
1834b41d939a1328f484511c6002ba2456db879a29Richard Smith  while (auto a = false) {
1934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
2034b41d939a1328f484511c6002ba2456db879a29Richard Smith
2134b41d939a1328f484511c6002ba2456db879a29Richard Smith  for (; auto a = false; ) {
2234b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
2334b41d939a1328f484511c6002ba2456db879a29Richard Smith
2434b41d939a1328f484511c6002ba2456db879a29Richard Smith  new const auto (0);
2534b41d939a1328f484511c6002ba2456db879a29Richard Smith  new (auto) (0.0);
2634b41d939a1328f484511c6002ba2456db879a29Richard Smith
277a614d8380297fcd2bc23986241905d97222948cRichard Smith  int arr[] = {1, 2, 3};
287a614d8380297fcd2bc23986241905d97222948cRichard Smith  for (auto i : arr) {
2934b41d939a1328f484511c6002ba2456db879a29Richard Smith  }
3034b41d939a1328f484511c6002ba2456db879a29Richard Smith}
317a614d8380297fcd2bc23986241905d97222948cRichard Smith
327a614d8380297fcd2bc23986241905d97222948cRichard Smithclass X {
337a614d8380297fcd2bc23986241905d97222948cRichard Smith  static const auto n = 'x';
347a614d8380297fcd2bc23986241905d97222948cRichard Smith
357a614d8380297fcd2bc23986241905d97222948cRichard Smith  auto m = 0; // expected-error {{'auto' not allowed in non-static class member}}
367a614d8380297fcd2bc23986241905d97222948cRichard Smith};
377a614d8380297fcd2bc23986241905d97222948cRichard Smith
387a614d8380297fcd2bc23986241905d97222948cRichard Smithstruct S {
394d4032206c9f966d991c73000e8816b910fb2fd7Chandler Carruth  static const auto a; // expected-error {{declaration of variable 'a' with type 'const auto' requires an initializer}}
407a614d8380297fcd2bc23986241905d97222948cRichard Smith  static const auto b = 0;
417a614d8380297fcd2bc23986241905d97222948cRichard Smith  static const int c;
427a614d8380297fcd2bc23986241905d97222948cRichard Smith};
437a614d8380297fcd2bc23986241905d97222948cRichard Smithconst int S::b;
447a614d8380297fcd2bc23986241905d97222948cRichard Smithconst auto S::c = 0;
45651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
46651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace std { template<typename T> struct initializer_list { initializer_list(); }; }
47651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
48651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// In an initializer of the form ( expression-list ), the expression-list
49651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// shall be a single assigment-expression.
50651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens1(1);
51651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens2(2, 3); // expected-error {{initializer for variable 'parens2' with type 'auto' contains multiple expressions}}
52651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#if __cplusplus >= 201103L
53651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens3({4, 5, 6}); // expected-error {{cannot deduce type for variable 'parens3' with type 'auto' from parenthesized initializer list}}
54651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens4 = [p4(1)] {};
55651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens5 = [p5(2, 3)] {}; // expected-error {{initializer for lambda capture 'p5' contains multiple expressions}}
56651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesauto parens6 = [p6({4, 5, 6})] {}; // expected-error {{cannot deduce type for lambda capture 'p6' from parenthesized initializer list}}
57651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#endif
58651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
59651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#if __cplusplus >= 201402L
60651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesnamespace std_example {
61651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  // The other half of this example is in p3.cpp
62651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  auto f() -> int;
63651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  auto g() { return 0.0; }
64651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  auto h();
65651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines}
66651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines#endif
67