]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7.cpp
Vendor import of clang trunk r300422:
[FreeBSD/FreeBSD.git] / test / CXX / dcl.dcl / dcl.spec / dcl.type / dcl.spec.auto / p7.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions
4 void f() {
5   auto a = 0, b = 0, c = 0;
6   auto d = 0, e = 0.0; // expected-error {{'int' in declaration of 'd' and deduced as 'double' in declaration of 'e'}}
7
8   auto v1 = 0, *p1 = &v1;
9   auto *p2 = 0, v2 = *p2; // expected-error {{incompatible initializer}}
10
11   const int k = 0;
12   auto &f = k, &g = a; // expected-error {{'const int' in declaration of 'f' and deduced as 'int' in declaration of 'g'}}
13
14   typedef int I;
15   I x;
16   auto xa = x, xb = 0;
17
18   auto &&ra1 = a, rb1 = b; // expected-error {{'int &' in declaration of 'ra1' and deduced as 'int' in declaration of 'rb1'}}
19   auto &&ra2 = +a, rb2 = b;
20 }
21
22 void g() {
23 #if __has_feature(cxx_trailing_return)
24   auto a = 0,
25        (*b)() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
26        c = 0;
27   auto d = 0,
28        e() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
29        f = 0.0;
30   auto x() -> void, // expected-error {{declaration with trailing return type must be the only declaration in its group}}
31        y() -> void;
32 #endif
33
34 #if __has_feature(cxx_decltype)
35   auto g = 0ull, h = decltype(g)(0);
36 #endif
37 }
38
39 #if __has_feature(cxx_trailing_return)
40 int F();
41 auto p = 0, (*q)() -> auto = F; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
42   #if __cplusplus < 201402L
43   // expected-error@-2 {{'auto' not allowed in function return type}}
44   #endif
45 #endif
46
47 #if __cplusplus >= 201402L
48 namespace DeducedReturnType {
49   auto a = 0,
50        b(), // expected-error {{function with deduced return type must be the only declaration in its group}}
51        c = 0.0;
52   auto d(), // expected-error {{function with deduced return type must be the only declaration in its group}}
53        e = 1;
54   auto f(), // expected-error {{function with deduced return type must be the only declaration in its group}}
55        g();
56 }
57 #endif
58
59 template<typename T> void h() {
60   auto a = T(), *b = &a;
61 #if __has_feature(cxx_decltype)
62   auto c = T(), d = decltype(c)(0);
63 #endif
64 }
65 template void h<int>();
66 template void h<unsigned long>();