]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
Vendor import of clang trunk r126079:
[FreeBSD/FreeBSD.git] / test / CXX / dcl.dcl / dcl.spec / dcl.type / dcl.spec.auto / p6.cpp
1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x
2
3 template<typename T>
4 struct only {
5   only(T);
6   template<typename U> only(U) = delete;
7 };
8
9 namespace N
10 {
11   auto a = "const char [16]", *p = &a;
12
13   only<const char [16]> testA = a;
14   only<const char **> testP = p;
15 }
16
17 void h() {
18   auto b = 42ULL;
19   only<unsigned long long> testB = b;
20
21   for (auto c = 0; c < 100; ++c) {
22     only<int> testC = c;
23   }
24 }
25
26 void p3example() {
27   auto x = 5;
28   const auto *v = &x, u = 6;
29   static auto y = 0.0;
30
31   only<int> testX = x;
32   only<const int*> testV = v;
33   only<const int> testU = u;
34   only<double> testY = y;
35 }
36
37 void f() {
38   if (auto a = true) {
39     only<bool> testA = a;
40   }
41
42   switch (auto a = 0) {
43   case 0:
44     only<int> testA = a;
45   }
46
47   while (auto a = false) {
48     only<bool> testA = a;
49   }
50
51   for (; auto a = "test"; ) {
52     only<const char[5]> testA = a;
53   }
54
55   auto *fail1 = 0; // expected-error {{variable 'fail1' with type 'auto *' has incompatible initializer of type 'int'}}
56   int **p;
57   // FIXME: due to PR9233, we get the wrong diagnostic here.
58   const auto **fail2(p); // desired-error {{variable 'fail2' with type 'auto const **' has incompatible initializer of type 'int **'}} expected-error {{cannot initialize}}
59 }
60
61 struct S {
62   void f();
63   char g(int);
64   float g(double);
65   int m;
66
67   void test() {
68     auto p1 = &S::f;
69     auto S::*p2 = &S::f;
70     auto (S::*p3)() = &S::f;
71     auto p4 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}}
72     auto S::*p5 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}}
73     auto (S::*p6)(int) = &S::g;
74     auto p7 = &S::m;
75     auto S::*p8 = &S::m;
76
77     only<void (S::*)()> test1 = p1;
78     only<void (S::*)()> test2 = p2;
79     only<void (S::*)()> test3 = p3;
80     only<char (S::*)(int)> test6 = p6;
81     only<int (S::*)> test7 = p7;
82     only<int (S::*)> test8 = p8;
83   }
84 };
85
86 // TODO: if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>.