79 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3namespace 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.15namespace 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 28namespace 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 do40 // better.41 int (A::*ptr)(int) = &(A::foo); // expected-error {{cannot create a non-constant pointer to member function}}42 }43}44 45namespace GH40906 {46struct 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 messages53 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};56static_assert(__is_same_as(decltype((S::x)), int&), "");57static_assert(__is_same_as(decltype(&(S::x)), int*), "");58static_assert(__is_same_as(decltype((S::func)), int&), ""); // expected-error {{call to non-static member function without an object argument}}59static_assert(__is_same_as(decltype(&(S::func)), int*), ""); // expected-error {{call to non-static member function without an object argument}}60 61struct A { int x;};62 63char q(int *);64short q(int A::*);65 66template <typename T>67constexpr int f(char (*)[sizeof(q(&T::x))]) { return 1; }68 69template <typename T>70constexpr int f(char (*)[sizeof(q(&(T::x)))]) { return 2; }71 72constexpr int g(char (*p)[sizeof(char)] = 0) { return f<A>(p); }73constexpr int h(char (*p)[sizeof(short)] = 0) { return f<A>(p); }74 75static_assert(g() == 2);76static_assert(h() == 1);77 78}79