1 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98 -Wno-c++11-extensions
3 
4 template<typename T>
5 struct only {
6   only(T);
7   template<typename U> only(U) = delete;
8 };
9 
10 namespace N
11 {
12   auto a = "const char [16]", *p = &a;
13 
14   only<const char [16]> testA = a;
15   only<const char **> testP = p;
16 }
17 
18 void h() {
19   auto b = 42ULL;
20   only<unsigned long long> testB = b;
21 
22   for (auto c = 0; c < 100; ++c) {
23     only<int> testC = c;
24   }
25 }
26 
27 void p3example() {
28   auto x = 5;
29   const auto *v = &x, u = 6;
30   static auto y = 0.0;
31 
32   only<int> testX = x;
33   only<const int*> testV = v;
34   only<const int> testU = u;
35   only<double> testY = y;
36 }
37 
38 void f() {
39   if (auto a = true) {
40     only<bool> testA = a;
41   }
42 
43   switch (auto a = 0) {
44   case 0:
45     only<int> testA = a;
46   }
47 
48   while (auto a = false) {
49     only<bool> testA = a;
50   }
51 
52   for (; auto a = "test"; ) {
53     only<const char[5]> testA = a;
54   }
55 
56   auto *fail1 = 0; // expected-error {{variable 'fail1' with type 'auto *' has incompatible initializer of type 'int'}}
57   int **p;
58   const auto **fail2(p); // expected-error {{variable 'fail2' with type 'const auto **' has incompatible initializer of type 'int **'}}
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 namespace PR10939 {
87   struct X {
88     int method(int); // expected-note{{possible target for call}}
89     int method(float); // expected-note{{possible target for call}}
90   };
91 
92   template<typename T> T g(T);
93 
94   void f(X *x) {
95     auto value = x->method; // expected-error {{reference to non-static member function must be called}}
96     if (value) { }
97 
98     auto funcptr = &g<int>;
99     int (*funcptr2)(int) = funcptr;
100   }
101 }
102 
103 // if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>:
104 // see SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
105