1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
2f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
3f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlstruct A {};
4f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlenum B { Dummy };
5f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlnamespace C {}
64433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redlstruct D : A {};
79e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct E : A {};
89e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct F : D, E {};
99e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct G : virtual D {};
10f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
11f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint A::*pdi1;
12f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint (::A::*pdi2);
13f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint (A::*pfi)(int);
14f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl
159ba6166f4a78722e7df8ffbd64eb788bfdf2764aJohn McCallint B::*pbi; // expected-error {{expected a class or namespace}}
16f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint C::*pci; // expected-error {{'pci' does not point into a class}}
17f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlvoid A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}}
188d4655d3b966da02fe0588767160448594cddd61Anders Carlssonint& A::*pdr; // expected-error {{'pdr' declared as a member pointer to a reference}}
198edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl
208edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redlvoid f() {
218edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl  // This requires tentative parsing.
228edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl  int (A::*pf)(int, int);
234433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl
244433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  // Implicit conversion to bool.
254433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  bool b = pdi1;
264433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  b = pfi;
274433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl
284433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  // Conversion from null pointer constant.
294433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  pf = 0;
304433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  pf = __null;
314433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl
324433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  // Conversion to member of derived.
334433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  int D::*pdid = pdi1;
344433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl  pdid = pdi2;
359e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redl
369e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redl  // Fail conversion due to ambiguity and virtuality.
377c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  int F::*pdif = pdi1; // expected-error {{ambiguous conversion from pointer to member of base class 'A' to pointer to member of derived class 'F':}}
387c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  int G::*pdig = pdi1; // expected-error {{conversion from pointer to member of class 'A' to pointer to member of class 'G' via virtual base 'D' is not allowed}}
3921593acb933324b439bc68b68e7cc7d1c3e3484dSebastian Redl
4021593acb933324b439bc68b68e7cc7d1c3e3484dSebastian Redl  // Conversion to member of base.
41d4eea8362605807327735727a9098abe1eb23b19Douglas Gregor  pdi1 = pdid; // expected-error {{assigning to 'int A::*' from incompatible type 'int D::*'}}
4220b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor
4320b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  // Comparisons
4420b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  int (A::*pf2)(int, int);
4520b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  int (D::*pf3)(int, int) = 0;
4620b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  bool b1 = (pf == pf2); (void)b1;
4720b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  bool b2 = (pf != pf2); (void)b2;
4820b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  bool b3 = (pf == pf3); (void)b3;
4920b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor  bool b4 = (pf != 0); (void)b4;
508edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl}
51ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl
5233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redlstruct TheBase
5333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl{
5433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void d();
5533b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl};
5633b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl
5733b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redlstruct HasMembers : TheBase
58ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl{
59ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  int i;
60ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  void f();
6133b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl
6233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void g();
6333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void g(int);
6433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  static void g(double);
65ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl};
66ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl
67ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redlnamespace Fake
68ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl{
69ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  int i;
70ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  void f();
71ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl}
72ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl
73ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redlvoid g() {
7433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  HasMembers hm;
7533b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl
76ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  int HasMembers::*pmi = &HasMembers::i;
77ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  int *pni = &Fake::i;
7833b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  int *pmii = &hm.i;
79ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl
8033b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void (HasMembers::*pmf)() = &HasMembers::f;
81ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl  void (*pnf)() = &Fake::f;
829c72c6088d591ace8503b842d39448c2040f3033John McCall  &hm.f; // expected-error {{cannot create a non-constant pointer to member function}}
8333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl
8433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void (HasMembers::*pmgv)() = &HasMembers::g;
8533b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void (HasMembers::*pmgi)(int) = &HasMembers::g;
8633b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void (*pmgd)(double) = &HasMembers::g;
8733b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl
8833b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl  void (HasMembers::*pmd)() = &HasMembers::d;
89ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl}
90224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
917d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregorstruct Incomplete;
927878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl
93224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlvoid h() {
94224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  HasMembers hm, *phm = &hm;
95224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
96224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  int HasMembers::*pi = &HasMembers::i;
97224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  hm.*pi = 0;
98224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  int i = phm->*pi;
99224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  (void)&(hm.*pi);
100224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  (void)&(phm->*pi);
10127d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian  (void)&((&hm)->*pi);
102224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
103224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  void (HasMembers::*pf)() = &HasMembers::f;
104224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  (hm.*pf)();
105224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  (phm->*pf)();
1067878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl
1077c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  (void)(hm->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'HasMembers'}}
1087c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  (void)(phm.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'HasMembers *'}}
1097878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  (void)(i.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}}
1107878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  int *ptr;
1117878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  (void)(ptr->*pi); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'int *'}}
1127878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl
1137878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  int A::*pai = 0;
1147878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  D d, *pd = &d;
1157878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  (void)(d.*pai);
1167878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  (void)(pd->*pai);
1177878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  F f, *ptrf = &f;
1187c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  (void)(f.*pai); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'F'}}
1197c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  (void)(ptrf->*pai); // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'F *'}}
1207878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl
121e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor  (void)(hm.*i); // expected-error {{pointer-to-member}}
122e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor  (void)(phm->*i); // expected-error {{pointer-to-member}}
1237878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl
1247d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregor  // Okay
1257878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  Incomplete *inc;
1267878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl  int Incomplete::*pii = 0;
1277d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregor  (void)(inc->*pii);
128224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl}
129224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
130224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlstruct OverloadsPtrMem
131224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl{
132224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  int operator ->*(const char *);
133224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl};
134224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl
135224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlvoid i() {
136224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  OverloadsPtrMem m;
137224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl  int foo = m->*"Awesome!";
138224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl}
139e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl
140e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redlnamespace pr5985 {
141e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl  struct c {
142e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl    void h();
143e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl    void f() {
144e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl      void (c::*p)();
145e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl      p = &h; // expected-error {{must explicitly qualify}}
1469c72c6088d591ace8503b842d39448c2040f3033John McCall      p = &this->h; // expected-error {{cannot create a non-constant pointer to member function}}
1479c72c6088d591ace8503b842d39448c2040f3033John McCall      p = &(*this).h; // expected-error {{cannot create a non-constant pointer to member function}}
148e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl    }
149e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl  };
150e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl}
15117e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl
15217e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redlnamespace pr6783 {
15317e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl  struct Base {};
15417e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl  struct X; // expected-note {{forward declaration}}
15517e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl
15617e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl  int test1(int Base::* p2m, X* object)
15717e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl  {
15817e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl    return object->*p2m; // expected-error {{left hand operand to ->*}}
15917e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl  }
16017e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl}
161e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor
162e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregornamespace PR7176 {
163e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  namespace base
164e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  {
165e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor    struct Process
166e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor    { };
167e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor    struct Continuous : Process
168e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor    {
169e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor      bool cond();
170e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor    };
171e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  }
172e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor
173e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  typedef bool( base::Process::*Condition )();
174e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor
175e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  void m()
176e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor  { (void)(Condition) &base::Continuous::cond; }
177e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor}
1789c72c6088d591ace8503b842d39448c2040f3033John McCall
1799c72c6088d591ace8503b842d39448c2040f3033John McCallnamespace rdar8358512 {
1809c72c6088d591ace8503b842d39448c2040f3033John McCall  // We can't call this with an overload set because we're not allowed
1819c72c6088d591ace8503b842d39448c2040f3033John McCall  // to look into overload sets unless the parameter has some kind of
1829c72c6088d591ace8503b842d39448c2040f3033John McCall  // function type.
1837114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  template <class F> void bind(F f); // expected-note 12 {{candidate template ignored}}
1849c72c6088d591ace8503b842d39448c2040f3033John McCall  template <class F, class T> void bindmem(F (T::*f)()); // expected-note 4 {{candidate template ignored}}
1859c72c6088d591ace8503b842d39448c2040f3033John McCall  template <class F> void bindfn(F (*f)()); // expected-note 4 {{candidate template ignored}}
1869c72c6088d591ace8503b842d39448c2040f3033John McCall
1879c72c6088d591ace8503b842d39448c2040f3033John McCall  struct A {
1889c72c6088d591ace8503b842d39448c2040f3033John McCall    void nonstat();
1899c72c6088d591ace8503b842d39448c2040f3033John McCall    void nonstat(int);
1909c72c6088d591ace8503b842d39448c2040f3033John McCall
1919c72c6088d591ace8503b842d39448c2040f3033John McCall    void mixed();
1929c72c6088d591ace8503b842d39448c2040f3033John McCall    static void mixed(int);
1939c72c6088d591ace8503b842d39448c2040f3033John McCall
1949c72c6088d591ace8503b842d39448c2040f3033John McCall    static void stat();
1959c72c6088d591ace8503b842d39448c2040f3033John McCall    static void stat(int);
1969c72c6088d591ace8503b842d39448c2040f3033John McCall
1979c72c6088d591ace8503b842d39448c2040f3033John McCall    template <typename T> struct Test0 {
1989c72c6088d591ace8503b842d39448c2040f3033John McCall      void test() {
1999c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&nonstat); // expected-error {{no matching function for call}}
2009c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&A::nonstat); // expected-error {{no matching function for call}}
2019c72c6088d591ace8503b842d39448c2040f3033John McCall
2029c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&mixed); // expected-error {{no matching function for call}}
2039c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&A::mixed); // expected-error {{no matching function for call}}
2049c72c6088d591ace8503b842d39448c2040f3033John McCall
2059c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&stat); // expected-error {{no matching function for call}}
2069c72c6088d591ace8503b842d39448c2040f3033John McCall        bind(&A::stat); // expected-error {{no matching function for call}}
2079c72c6088d591ace8503b842d39448c2040f3033John McCall      }
2089c72c6088d591ace8503b842d39448c2040f3033John McCall    };
2099c72c6088d591ace8503b842d39448c2040f3033John McCall
2109c72c6088d591ace8503b842d39448c2040f3033John McCall    template <typename T> struct Test1 {
2119c72c6088d591ace8503b842d39448c2040f3033John McCall      void test() {
2129c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&nonstat); // expected-error {{no matching function for call}}
2139c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&A::nonstat);
2149c72c6088d591ace8503b842d39448c2040f3033John McCall
2159c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&mixed); // expected-error {{no matching function for call}}
2169c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&A::mixed);
2179c72c6088d591ace8503b842d39448c2040f3033John McCall
2189c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&stat); // expected-error {{no matching function for call}}
2199c72c6088d591ace8503b842d39448c2040f3033John McCall        bindmem(&A::stat); // expected-error {{no matching function for call}}
2209c72c6088d591ace8503b842d39448c2040f3033John McCall      }
2219c72c6088d591ace8503b842d39448c2040f3033John McCall    };
2229c72c6088d591ace8503b842d39448c2040f3033John McCall
2239c72c6088d591ace8503b842d39448c2040f3033John McCall    template <typename T> struct Test2 {
2249c72c6088d591ace8503b842d39448c2040f3033John McCall      void test() {
2259c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&nonstat); // expected-error {{no matching function for call}}
2269c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&A::nonstat); // expected-error {{no matching function for call}}
2279c72c6088d591ace8503b842d39448c2040f3033John McCall
2289c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&mixed); // expected-error {{no matching function for call}}
2299c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&A::mixed); // expected-error {{no matching function for call}}
2309c72c6088d591ace8503b842d39448c2040f3033John McCall
2319c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&stat);
2329c72c6088d591ace8503b842d39448c2040f3033John McCall        bindfn(&A::stat);
2339c72c6088d591ace8503b842d39448c2040f3033John McCall      }
2349c72c6088d591ace8503b842d39448c2040f3033John McCall    };
2359c72c6088d591ace8503b842d39448c2040f3033John McCall  };
2367114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2377114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  template <class T> class B {
2387114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    void nonstat();
2397114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    void nonstat(int);
2407114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2417114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    void mixed();
2427114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    static void mixed(int);
2437114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2447114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    static void stat();
2457114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    static void stat(int);
2467114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2477114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    // None of these can be diagnosed yet, because the arguments are
2487114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    // still dependent.
2497114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    void test0a() {
2507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&nonstat);
2517114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::nonstat);
2527114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2537114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&mixed);
2547114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::mixed);
2557114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2567114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&stat);
2577114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::stat);
2587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
2597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2607114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    void test0b() {
2617114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&nonstat); // expected-error {{no matching function for call}}
2627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::nonstat); // expected-error {{no matching function for call}}
2637114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&mixed); // expected-error {{no matching function for call}}
2657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::mixed); // expected-error {{no matching function for call}}
2667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&stat); // expected-error {{no matching function for call}}
2687114cbab7eb6e8b714eb22f014327daf2c741c08John McCall      bind(&B::stat); // expected-error {{no matching function for call}}
2697114cbab7eb6e8b714eb22f014327daf2c741c08John McCall    }
2707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  };
2717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall
2727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall  template void B<int>::test0b(); // expected-note {{in instantiation}}
2739c72c6088d591ace8503b842d39448c2040f3033John McCall}
274b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor
275b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregornamespace PR9973 {
276b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  template<class R, class T> struct dm
277b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  {
278b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    typedef R T::*F;
279b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    F f_;
280b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    template<class U> int & call(U u)
2815acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    { return u->*f_; } // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}} expected-error {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
282b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor
283b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    template<class U> int operator()(U u)
284b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    { call(u); } // expected-note{{in instantiation of}}
285b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  };
286b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor
287b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  template<class R, class T>
288b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  dm<R, T> mem_fn(R T::*) ;
289b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor
290b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  struct test
291b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  { int nullary_v(); };
292b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor
293b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  void f()
294b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  {
295b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    test* t;
296b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor    mem_fn(&test::nullary_v)(t); // expected-note{{in instantiation of}}
297b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor  }
298b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor}
299ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall
300ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCallnamespace test8 {
301ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall  struct A { int foo; };
302ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall  int test1() {
303ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall    // Verify that we perform (and check) an lvalue conversion on the operands here.
304ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall    return (*((A**) 0)) // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
305ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall             ->**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
306ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall  }
307ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall
308ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall  int test2() {
309ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall    // Verify that we perform (and check) an lvalue conversion on the operands here.
310ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall    // TODO: the .* should itself warn about being a dereference of null.
311ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall    return (*((A*) 0))
312ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall             .**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}}
313ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall  }
314ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall}
315