summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-01-13 02:22:01 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-01-13 02:22:01 +0000
commit8210ed558662bd80f16bc96e482974120d2ca2bd (patch)
tree8cf39a448668eefe9889917924585318c2ca93a2 /clang/test
parent8515875e24831bda1ca3086da17163836100d30b (diff)
downloadbcm5719-llvm-8210ed558662bd80f16bc96e482974120d2ca2bd.tar.gz
bcm5719-llvm-8210ed558662bd80f16bc96e482974120d2ca2bd.zip
Implement DR1265 (wg21.link/cwg1265).
Diasllow a declaration using the 'auto' type specifier from using two different meanings of it at once, or from declaring multiple functions with deduced return types or introducing multiple trailing return types. The standard does not technically disallow the multiple trailing return types case if all the declarators declare variables (such as function pointers with trailing return types), but we disallow that too, following the clear intent. llvm-svn: 291880
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp35
-rw-r--r--clang/test/CXX/drs/dr12xx.cpp20
-rw-r--r--clang/test/CXX/drs/dr13xx.cpp19
3 files changed, 64 insertions, 10 deletions
diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp
index 8d789bdd5ad..e9294d7f436 100644
--- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp
@@ -1,3 +1,4 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions
void f() {
@@ -19,22 +20,42 @@ void f() {
}
void g() {
- auto a = 0,
#if __has_feature(cxx_trailing_return)
- (*b)() -> void,
-#endif
+ auto a = 0,
+ (*b)() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
c = 0;
- auto d = 0, // expected-error {{'auto' deduced as 'int' in declaration of 'd' and deduced as 'double' in declaration of 'f'}}
-#if __has_feature(cxx_trailing_return)
- (*e)() -> void,
-#endif
+ auto d = 0,
+ e() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
f = 0.0;
+ auto x() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+ y() -> void;
+#endif
#if __has_feature(cxx_decltype)
auto g = 0ull, h = decltype(g)(0);
#endif
}
+#if __has_feature(cxx_trailing_return)
+int F();
+auto p = 0, (*q)() -> auto = F; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+ #if __cplusplus < 201402L
+ // expected-error@-2 {{'auto' not allowed in function return type}}
+ #endif
+#endif
+
+#if __cplusplus >= 201402L
+namespace DeducedReturnType {
+ auto a = 0,
+ b(), // expected-error {{function with deduced return type must be the only declaration in its group}}
+ c = 0.0;
+ auto d(), // expected-error {{function with deduced return type must be the only declaration in its group}}
+ e = 1;
+ auto f(), // expected-error {{function with deduced return type must be the only declaration in its group}}
+ g();
+}
+#endif
+
template<typename T> void h() {
auto a = T(), *b = &a;
#if __has_feature(cxx_decltype)
diff --git a/clang/test/CXX/drs/dr12xx.cpp b/clang/test/CXX/drs/dr12xx.cpp
index 45b33f9d7da..24039a1cd24 100644
--- a/clang/test/CXX/drs/dr12xx.cpp
+++ b/clang/test/CXX/drs/dr12xx.cpp
@@ -14,7 +14,7 @@ namespace dr1213 { // dr1213: 4
#endif
}
-namespace dr1250 { // dr1250: 3.9
+namespace dr1250 { // dr1250: 3.9
struct Incomplete;
struct Base {
@@ -24,9 +24,23 @@ struct Base {
struct Derived : Base {
virtual Incomplete *meow();
};
-} // dr1250
+}
+
+namespace dr1265 { // dr1265: 5
+#if __cplusplus >= 201103L
+ auto a = 0, b() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+ auto b() -> int, d = 0; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+ auto e() -> int, f() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+#endif
+
+#if __cplusplus >= 201402L
+ auto g(), h = 0; // expected-error {{function with deduced return type must be the only declaration in its group}}
+ auto i = 0, j(); // expected-error {{function with deduced return type must be the only declaration in its group}}
+ auto k(), l(); // expected-error {{function with deduced return type must be the only declaration in its group}}
+#endif
+}
-namespace dr1295 { // dr1295: 4
+namespace dr1295 { // dr1295: 4
struct X {
unsigned bitfield : 4;
};
diff --git a/clang/test/CXX/drs/dr13xx.cpp b/clang/test/CXX/drs/dr13xx.cpp
index f35ead7b5e9..a4223ffb908 100644
--- a/clang/test/CXX/drs/dr13xx.cpp
+++ b/clang/test/CXX/drs/dr13xx.cpp
@@ -3,6 +3,16 @@
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
+__extension__ typedef __SIZE_TYPE__ size_t;
+
+namespace std {
+ template<typename T> struct initializer_list {
+ const T *ptr;
+ size_t n;
+ initializer_list(const T*, size_t);
+ };
+}
+
namespace dr1315 { // dr1315: partial
template <int I, int J> struct A {};
template <int I> // expected-note {{non-deducible template parameter 'I'}}
@@ -159,6 +169,15 @@ namespace dr1346 { // dr1346: 3.5
#endif
}
+namespace dr1347 { // dr1347: yes
+ auto x = 5, *y = &x; // expected-error 0-1{{extension}}
+ auto z = y, *q = y; // expected-error {{'auto' deduced as 'int *' in declaration of 'z' and deduced as 'int' in declaration of 'q'}} expected-error 0-1{{extension}}
+#if __cplusplus >= 201103L
+ auto a = 5, b = {1, 2}; // expected-error {{'auto' deduced as 'int' in declaration of 'a' and deduced as 'std::initializer_list<int>' in declaration of 'b'}}
+ auto (*fp)(int) -> int, i = 0; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
+#endif
+}
+
namespace dr1359 { // dr1359: 3.5
#if __cplusplus >= 201103L
union A { constexpr A() = default; };
OpenPOWER on IntegriCloud