summaryrefslogtreecommitdiffstats
path: root/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp
blob: 682ee9f7e4ec94e345ead87ee531400405eaa8eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++0x-extensions
void f() {
  auto a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}}
  auto *b = b; // expected-error{{variable 'b' declared with 'auto' type cannot appear in its own initializer}}
  const auto c = c; // expected-error{{variable 'c' declared with 'auto' type cannot appear in its own initializer}}
  if (auto d = d) {} // expected-error {{variable 'd' declared with 'auto' type cannot appear in its own initializer}}
  auto e = ({ auto f = e; 0; }); // expected-error {{variable 'e' declared with 'auto' type cannot appear in its own initializer}}
}

void g() {
  auto a; // expected-error{{declaration of variable 'a' with type 'auto' requires an initializer}}
  
  auto *b; // expected-error{{declaration of variable 'b' with type 'auto *' requires an initializer}}

  if (auto b) {} // expected-error {{expected '='}}
  for (;auto b;) {} // expected-error {{expected '='}}
  while (auto b) {} // expected-error {{expected '='}}
  if (auto b = true) { (void)b; }
}

auto n(1,2,3); // expected-error{{initializer for variable 'n' with type 'auto' contains multiple expressions}}

namespace N
{
  auto a = "const char [16]", *p = &a;
}

void h() {
  auto b = 42ULL;

  for (auto c = 0; c < b; ++c) {
  }
}

template<typename T, typename U> struct same;
template<typename T> struct same<T, T> {};

void p3example() {
  auto x = 5;
  const auto *v = &x, u = 6;
  static auto y = 0.0;
  // In C++98: 'auto' storage class specifier is redundant and incompatible with C++0x
  // In C++0x: 'auto' storage class specifier is not permitted in C++0x, and will not be supported in future releases
  auto int r; // expected-warning {{'auto' storage class specifier}}

  same<__typeof(x), int> xHasTypeInt;
  same<__typeof(v), const int*> vHasTypeConstIntPtr;
  same<__typeof(u), const int> uHasTypeConstInt;
  same<__typeof(y), double> yHasTypeDouble;
}