p5.cpp revision 34b41d939a1328f484511c6002ba2456db879a29
1// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s -std=c++0x
2
3struct S {
4  virtual ~S();
5
6  auto a; // expected-error{{'auto' not allowed in struct member}}
7  auto *b; // expected-error{{'auto' not allowed in struct member}}
8  const auto c; // expected-error{{'auto' not allowed in struct member}}
9
10  void f() throw (auto); // expected-error{{'auto' not allowed here}}
11
12  friend auto; // expected-error{{'auto' not allowed in struct member}}
13
14  operator auto(); // expected-error{{'auto' not allowed here}}
15};
16
17void g(auto a) { // expected-error{{'auto' not allowed in function prototype}}
18  try { }
19  catch (auto &a) { } // expected-error{{'auto' not allowed in exception declaration}}
20  catch (const auto a) { } // expected-error{{'auto' not allowed in exception declaration}}
21  try { } catch (auto a) { } // expected-error{{'auto' not allowed in exception declaration}}
22}
23
24void h(auto a[10]) { // expected-error{{'auto' not allowed in function prototype}}
25}
26
27void i(const auto a) { // expected-error{{'auto' not allowed in function prototype}}
28}
29
30namespace std {
31  class type_info;
32}
33
34template<typename T> struct U {};
35
36void j() {
37  (void)typeid(auto); // expected-error{{'auto' not allowed here}}
38  (void)sizeof(auto); // expected-error{{'auto' not allowed here}}
39  (void)__alignof(auto); // expected-error{{'auto' not allowed here}}
40
41  // FIXME: don't issue the second diagnostic for this error.
42  U<auto> v; // expected-error{{'auto' not allowed in template argument}} unexpected-error{{C++ requires a type specifier}}
43
44  int n;
45  (void)dynamic_cast<auto&>(S()); // expected-error{{'auto' not allowed here}}
46  (void)static_cast<auto*>(&n); // expected-error{{'auto' not allowed here}}
47  (void)reinterpret_cast<auto*>(&n); // expected-error{{'auto' not allowed here}}
48  (void)const_cast<auto>(n); // expected-error{{'auto' not allowed here}}
49  (void)*(auto*)(&n); // expected-error{{'auto' not allowed here}}
50  (void)auto(n); // expected-error{{expected expression}}
51  (void)auto{n}; // expected-error{{expected expression}}
52}
53
54template <auto a = 10> class C { }; // expected-error{{'auto' not allowed in template parameter}}
55int ints[] = {1, 2, 3};
56template <const auto (*a)[3] = &ints> class D { }; // expected-error{{'auto' not allowed in template parameter}}
57enum E : auto {}; // expected-error{{'auto' not allowed here}}
58struct F : auto {}; // expected-error{{expected class name}}
59template<typename T = auto> struct G { }; // expected-error{{'auto' not allowed here}}
60
61using A = auto; // expected-error{{expected ';'}} expected-error{{requires a qualified name}}
62
63// Whether this is illegal depends on the interpretation of [decl.spec.auto]p2 and p3,
64// and in particular the "Otherwise, ..." at the start of p3.
65namespace TrailingReturnType {
66  // FIXME: don't issue the second diagnostic for this error.
67  auto f() -> auto; // expected-error{{'auto' not allowed here}} unexpected-error{{without trailing return type}}
68  int g();
69  auto (*h)() -> auto = &g; // expected-error{{'auto' not allowed here}}
70  auto (*i)() = &g; // ok; auto deduced as int.
71  auto (*j)() -> int = i; // ok; no deduction.
72}
73