aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/dcl.dcl
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-04-26 16:15:35 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-04-26 16:15:35 +0000
commita2c3646c35dd09d21b74826240aa916545b1873f (patch)
treee2a57dcc3d41734ea9734c76a9d759c8951392f4 /test/CXX/dcl.dcl
parentbebf5b1bcfbf591dd3cd80c4aebd6486bb34f41c (diff)
Implement C++1y decltype(auto).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180610 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/dcl.dcl')
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp43
-rw-r--r--test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp62
2 files changed, 105 insertions, 0 deletions
diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp
new file mode 100644
index 0000000000..7245b9b47f
--- /dev/null
+++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p3-1y.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++1y
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11 -Wno-c++1y-extensions
+
+// FIXME: This is in p11 (?) in C++1y.
+void f() {
+ decltype(auto) a = a; // expected-error{{variable 'a' declared with 'auto' type cannot appear in its own initializer}}
+ if (decltype(auto) b = b) {} // expected-error {{variable 'b' declared with 'auto' type cannot appear in its own initializer}}
+ decltype(auto) c = ({ decltype(auto) d = c; 0; }); // expected-error {{variable 'c' declared with 'auto' type cannot appear in its own initializer}}
+}
+
+void g() {
+ decltype(auto) a; // expected-error{{declaration of variable 'a' with type 'decltype(auto)' requires an initializer}}
+
+ decltype(auto) *b; // expected-error{{cannot form pointer to 'decltype(auto)'}} expected-error{{declaration of variable 'b' with type 'decltype(auto) *' requires an initializer}}
+
+ if (decltype(auto) b) {} // expected-error {{must have an initializer}}
+ for (;decltype(auto) b;) {} // expected-error {{must have an initializer}}
+ while (decltype(auto) b) {} // expected-error {{must have an initializer}}
+ if (decltype(auto) b = true) { (void)b; }
+}
+
+decltype(auto) n(1,2,3); // expected-error{{initializer for variable 'n' with type 'decltype(auto)' contains multiple expressions}}
+
+namespace N
+{
+ // All of these are references, because a string literal is an lvalue.
+ decltype(auto) a = "const char (&)[19]", b = a, c = (a);
+}
+
+void h() {
+ decltype(auto) b = 42ULL;
+
+ for (decltype(auto) c = 0; c < b; ++c) {
+ }
+}
+
+template<typename T, typename U> struct same;
+template<typename T> struct same<T, T> {};
+
+void i() {
+ decltype(auto) x = 5;
+ decltype(auto) int r; // expected-error {{cannot combine with previous 'decltype(auto)' declaration specifier}} expected-error {{requires an initializer}}
+}
diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp
new file mode 100644
index 0000000000..cfaed71832
--- /dev/null
+++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6-1y.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -verify -std=c++1y %s
+
+namespace std {
+ template<typename T> struct initializer_list {
+ const T *p;
+ unsigned long n;
+ initializer_list(const T *p, unsigned long n);
+ };
+}
+
+// FIXME: This may not be p6 in C++1y; N3638 isn't very clear whether paragraphs
+// were added. It might be p8?
+
+int i;
+int &&f();
+
+using Int = int;
+using IntLRef = int&;
+using IntRRef = int&&;
+using InitListInt = std::initializer_list<int>;
+using IntPtr = int*;
+
+auto x3a = i;
+decltype(auto) x3d = i;
+using Int = decltype(x3a);
+using Int = decltype(x3d);
+
+auto x4a = (i);
+decltype(auto) x4d = (i);
+using Int = decltype(x4a);
+using IntLRef = decltype(x4d);
+
+auto x5a = f();
+decltype(auto) x5d = f();
+using Int = decltype(x5a);
+using IntRRef = decltype(x5d);
+
+auto x6a = { 1, 2 };
+decltype(auto) x6d = { 1, 2 }; // expected-error {{cannot deduce 'decltype(auto)' from initializer list}}
+using InitListInt = decltype(x6a);
+
+auto *x7a = &i;
+decltype(auto) *x7d = &i; // expected-error {{cannot form pointer to 'decltype(auto)'}}
+using IntPtr = decltype(x7a);
+
+struct S {};
+
+decltype(auto) f1();
+decltype(auto) (*f2)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}}
+decltype(auto) *f3(); // expected-error {{cannot form pointer to 'decltype(auto)'}}
+const decltype(auto) f4(); // expected-error {{'decltype(auto)' cannot be combined with other type specifiers}}
+typedef decltype(auto) f5(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}}
+decltype(auto) ((((((f6))))())); // ok
+decltype(auto) f7()(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{function cannot return function type}}
+decltype(auto) (S::*f8)(); // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}} expected-error {{requires an initializer}}
+decltype(auto) &f9(); // expected-error {{cannot form reference to 'decltype(auto)'}}
+decltype(auto) (&f10())[10]; // expected-error {{cannot form array of 'decltype(auto)'}}
+
+decltype(auto) ((((((v1)))))) = 0; // ok
+decltype(auto) v2[1] = { 0 }; // expected-error {{cannot form array of 'decltype(auto)'}}
+decltype(auto) &v3 = { 0 }; // expected-error {{cannot form reference to 'decltype(auto)'}}
+decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}}