1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 3 namespace test0 { 4 struct A { 5 void foo(void (A::*)(int)); // expected-note {{passing argument to parameter here}} 6 template<typename T> void g(T); 7 8 void test() { 9 foo(&g<int>); // expected-error-re {{cannot form member pointer of type 'void (A::*)(int){{( __attribute__\(\(thiscall\)\))?}}' without '&' and class name}} 10 } 11 }; 12 } 13 14 // This should succeed. 15 namespace test1 { 16 struct A { 17 static void f(void (A::*)()); 18 static void f(void (*)(int)); 19 void g(); 20 static void g(int); 21 22 void test() { 23 f(&g); 24 } 25 }; 26 } 27 28 namespace test2 { 29 struct A { 30 static int foo(short); 31 static int foo(float); 32 int foo(int); 33 int foo(double); 34 35 void test(); 36 }; 37 38 void A::test() { 39 // FIXME: The error message in this case is less than clear, we can do 40 // better. 41 int (A::*ptr)(int) = &(A::foo); // expected-error {{cannot create a non-constant pointer to member function}} 42 } 43 } 44 45 namespace GH40906 { 46 struct S { 47 int x; 48 void func(); 49 static_assert(__is_same_as(decltype((S::x)), int&), ""); 50 static_assert(__is_same_as(decltype(&(S::x)), int*), ""); 51 52 // FIXME: provide better error messages 53 static_assert(__is_same_as(decltype((S::func)), int&), ""); // expected-error {{call to non-static member function without an object argument}} 54 static_assert(__is_same_as(decltype(&(S::func)), int*), ""); // expected-error {{call to non-static member function without an object argument}} 55 }; 56 static_assert(__is_same_as(decltype((S::x)), int&), ""); 57 static_assert(__is_same_as(decltype(&(S::x)), int*), ""); 58 static_assert(__is_same_as(decltype((S::func)), int&), ""); // expected-error {{call to non-static member function without an object argument}} 59 static_assert(__is_same_as(decltype(&(S::func)), int*), ""); // expected-error {{call to non-static member function without an object argument}} 60 61 struct A { int x;}; 62 63 char q(int *); 64 short q(int A::*); 65 66 template <typename T> 67 constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; } 68 69 template <typename T> 70 constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; } 71 72 constexpr int g(char (*p)[sizeof(char)] = 0) { return f<A>(p); } 73 constexpr int h(char (*p)[sizeof(short)] = 0) { return f<A>(p); } 74 75 static_assert(g() == 2); 76 static_assert(h() == 1); 77 78 } 79