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