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