diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-26 22:09:03 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-26 22:09:03 +0000 |
| commit | c3b054d250cdca485c71845089c316e10610ebad (patch) | |
| tree | abae0246ec9156cc1a7cbb947b2b0dfe95fa3189 /test/CXX/dcl.dcl | |
| parent | bca07a4524feb4edec581062d631a13116320a24 (diff) | |
Notes
Diffstat (limited to 'test/CXX/dcl.dcl')
3 files changed, 65 insertions, 12 deletions
diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp new file mode 100644 index 0000000000000..18a0cf169d549 --- /dev/null +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp @@ -0,0 +1,49 @@ +// RUN: %clang_cc1 -fexceptions -fsyntax-only -verify %s -std=c++0x + +struct S { + virtual ~S(); + + void g() throw (auto(*)()->int); + + // Note, this is not permitted: conversion-declarator cannot have a trailing return type. + // FIXME: don't issue the second diagnostic for this. + operator auto(*)()->int(); // expected-error{{'auto' not allowed here}} expected-error {{C++ requires a type specifier}} +}; + +typedef auto Fun(int a) -> decltype(a + a); +typedef auto (*PFun)(int a) -> decltype(a + a); + +void g(auto (*f)() -> int) { + try { } + catch (auto (&f)() -> int) { } + catch (auto (*const f[10])() -> int) { } +} + +namespace std { + class type_info; +} + +template<typename T> struct U {}; + +void j() { + (void)typeid(auto(*)()->void); + (void)sizeof(auto(*)()->void); + (void)__alignof(auto(*)()->void); + + U<auto(*)()->void> v; + + int n; + (void)static_cast<auto(*)()->void>(&j); + auto p = reinterpret_cast<auto(*)()->int>(&j); + (void)const_cast<auto(**)()->int>(&p); + (void)(auto(*)()->void)(&j); +} + +template <auto (*f)() -> void = &j> class C { }; +struct F : auto(*)()->int {}; // expected-error{{expected class name}} +template<typename T = auto(*)()->int> struct G { }; + +int g(); +auto (*h)() -> auto = &g; // expected-error{{'auto' not allowed here}} +auto (*i)() = &g; // ok; auto deduced as int. +auto (*k)() -> int = i; // ok; no deduction. diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp index 24780c68322ca..b675fb8013e37 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp @@ -3,12 +3,19 @@ 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}} @@ -21,7 +28,7 @@ namespace N void h() { auto b = 42ULL; - for (auto c = 0; c < 100; ++c) { + for (auto c = 0; c < b; ++c) { } } @@ -32,7 +39,7 @@ void p3example() { auto x = 5; const auto *v = &x, u = 6; static auto y = 0.0; - auto int r; // expected-error{{cannot combine with previous}} expected-error{{requires an initializer}} + auto int r; // expected-warning {{'auto' storage class specifier is redundant and will be removed in future releases}} same<decltype(x), int> xHasTypeInt; same<decltype(v), const int*> vHasTypeConstIntPtr; diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp index 836ccda6f9d72..fec53c941e3d3 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp @@ -14,6 +14,11 @@ struct S { operator auto(); // expected-error{{'auto' not allowed here}} }; +// PR 9278: auto is not allowed in typedefs, except with a trailing return type. +typedef auto *AutoPtr; // expected-error{{'auto' not allowed in typedef}} +typedef auto (*PFun)(int a); // expected-error{{'auto' not allowed in typedef}} +typedef auto Fun(int a) -> decltype(a + a); + void g(auto a) { // expected-error{{'auto' not allowed in function prototype}} try { } catch (auto &a) { } // expected-error{{'auto' not allowed in exception declaration}} @@ -60,13 +65,5 @@ template<typename T = auto> struct G { }; // expected-error{{'auto' not allowed using A = auto; // expected-error{{expected ';'}} expected-error{{requires a qualified name}} -// Whether this is illegal depends on the interpretation of [decl.spec.auto]p2 and p3, -// and in particular the "Otherwise, ..." at the start of p3. -namespace TrailingReturnType { - // FIXME: don't issue the second diagnostic for this error. - auto f() -> auto; // expected-error{{'auto' not allowed here}} unexpected-error{{without trailing return type}} - int g(); - auto (*h)() -> auto = &g; // expected-error{{'auto' not allowed here}} - auto (*i)() = &g; // ok; auto deduced as int. - auto (*j)() -> int = i; // ok; no deduction. -} +// FIXME: don't issue the second diagnostic for this error. +auto k() -> auto; // expected-error{{'auto' not allowed here}} unexpected-error{{without trailing return type}} |
