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