summaryrefslogtreecommitdiffstats
path: root/test/CXX
diff options
context:
space:
mode:
Diffstat (limited to 'test/CXX')
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p2.cpp49
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3.cpp11
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp17
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp2
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8-0x.cpp6
-rw-r--r--test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp3
6 files changed, 76 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 0000000..18a0cf1
--- /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 24780c6..b675fb8 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 836ccda..fec53c9 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}}
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
index 4dc393d..70c9aeb 100644
--- a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
@@ -3,3 +3,5 @@
auto a() -> int; // ok
const auto b() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'auto const'}}
auto *c() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'auto *'}}
+auto (d() -> int); // expected-error {{trailing return type may not be nested within parentheses}}
+auto e() -> auto (*)() -> auto (*)() -> void; // ok: same as void (*(*e())())();
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8-0x.cpp
new file mode 100644
index 0000000..21efbff
--- /dev/null
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8-0x.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+auto f() -> int[32]; // expected-error{{function cannot return array}}
+auto g() -> int(int); // expected-error{{function cannot return function}}
+auto h() -> auto() -> int; // expected-error{{function cannot return function}}
+auto i() -> auto(*)() -> int;
diff --git a/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
new file mode 100644
index 0000000..ca47015
--- /dev/null
+++ b/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+auto j() -> enum { e3 }; // expected-error{{can not be defined in a type specifier}}
OpenPOWER on IntegriCloud