p6.cpp revision 9a636e8403287af0d4db8fe5bf49dee719f5b754
1// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++0x 2 3template<typename T> 4struct only { 5 only(T); 6 template<typename U> only(U) = delete; 7}; 8 9namespace 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 17void 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 26void 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 37void 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 const auto **fail2(p); // expected-error {{variable 'fail2' with type 'auto const **' has incompatible initializer of type 'int **'}} 58} 59 60struct S { 61 void f(); 62 char g(int); 63 float g(double); 64 int m; 65 66 void test() { 67 auto p1 = &S::f; 68 auto S::*p2 = &S::f; 69 auto (S::*p3)() = &S::f; 70 auto p4 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}} 71 auto S::*p5 = &S::g; // expected-error {{incompatible initializer of type '<overloaded function type>'}} 72 auto (S::*p6)(int) = &S::g; 73 auto p7 = &S::m; 74 auto S::*p8 = &S::m; 75 76 only<void (S::*)()> test1 = p1; 77 only<void (S::*)()> test2 = p2; 78 only<void (S::*)()> test3 = p3; 79 only<char (S::*)(int)> test6 = p6; 80 only<int (S::*)> test7 = p7; 81 only<int (S::*)> test8 = p8; 82 } 83}; 84 85// TODO: if the initializer is a braced-init-list, deduce auto as std::initializer_list<T>. 86