1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s 2*f4a2713aSLionel Sambuc struct Y { 3*f4a2713aSLionel Sambuc int x; 4*f4a2713aSLionel Sambuc }; 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc template<typename T> 7*f4a2713aSLionel Sambuc struct X1 { 8*f4a2713aSLionel Sambuc int f(T* ptr, int T::*pm) { // expected-error{{member pointer}} 9*f4a2713aSLionel Sambuc return ptr->*pm; 10*f4a2713aSLionel Sambuc } 11*f4a2713aSLionel Sambuc }; 12*f4a2713aSLionel Sambuc 13*f4a2713aSLionel Sambuc template struct X1<Y>; 14*f4a2713aSLionel Sambuc template struct X1<int>; // expected-note{{instantiation}} 15*f4a2713aSLionel Sambuc 16*f4a2713aSLionel Sambuc template<typename T, typename Class> 17*f4a2713aSLionel Sambuc struct X2 { 18*f4a2713aSLionel Sambuc T f(Class &obj, T Class::*pm) { // expected-error{{to a reference}} \ 19*f4a2713aSLionel Sambuc // expected-error{{member pointer to void}} 20*f4a2713aSLionel Sambuc return obj.*pm; 21*f4a2713aSLionel Sambuc } 22*f4a2713aSLionel Sambuc }; 23*f4a2713aSLionel Sambuc 24*f4a2713aSLionel Sambuc template struct X2<int, Y>; 25*f4a2713aSLionel Sambuc template struct X2<int&, Y>; // expected-note{{instantiation}} 26*f4a2713aSLionel Sambuc template struct X2<const void, Y>; // expected-note{{instantiation}} 27*f4a2713aSLionel Sambuc 28*f4a2713aSLionel Sambuc template<typename T, typename Class, T Class::*Ptr> 29*f4a2713aSLionel Sambuc struct X3 { 30*f4a2713aSLionel Sambuc X3<T, Class, Ptr> &operator=(const T& value) { 31*f4a2713aSLionel Sambuc return *this; 32*f4a2713aSLionel Sambuc } 33*f4a2713aSLionel Sambuc }; 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc X3<int, Y, &Y::x> x3; 36*f4a2713aSLionel Sambuc 37*f4a2713aSLionel Sambuc typedef int Y::*IntMember; 38*f4a2713aSLionel Sambuc 39*f4a2713aSLionel Sambuc template<IntMember Member> 40*f4a2713aSLionel Sambuc struct X4 { 41*f4a2713aSLionel Sambuc X3<int, Y, Member> member; 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc int &getMember(Y& y) { return y.*Member; } 44*f4a2713aSLionel Sambuc }; 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc int &get_X4(X4<&Y::x> x4, Y& y) { 47*f4a2713aSLionel Sambuc return x4.getMember(y); 48*f4a2713aSLionel Sambuc } 49*f4a2713aSLionel Sambuc 50*f4a2713aSLionel Sambuc template<IntMember Member> 51*f4a2713aSLionel Sambuc void accept_X4(X4<Member>); 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc void test_accept_X4(X4<&Y::x> x4) { 54*f4a2713aSLionel Sambuc accept_X4(x4); 55*f4a2713aSLionel Sambuc } 56*f4a2713aSLionel Sambuc 57*f4a2713aSLionel Sambuc namespace ValueDepMemberPointer { 58*f4a2713aSLionel Sambuc template <void (*)()> struct instantiate_function {}; 59*f4a2713aSLionel Sambuc template <typename T> struct S { 60*f4a2713aSLionel Sambuc static void instantiate(); 61*f4a2713aSLionel Sambuc typedef instantiate_function<&S::instantiate> x; // expected-note{{instantiation}} 62*f4a2713aSLionel Sambuc }; 63*f4a2713aSLionel Sambuc template <typename T> void S<T>::instantiate() { 64*f4a2713aSLionel Sambuc int a[(int)sizeof(T)-42]; // expected-error{{array with a negative size}} 65*f4a2713aSLionel Sambuc } 66*f4a2713aSLionel Sambuc S<int> s; 67*f4a2713aSLionel Sambuc } 68