1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s 287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s 387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s 4f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 5f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlstruct A {}; 6f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlenum B { Dummy }; 7f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlnamespace C {} 84433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redlstruct D : A {}; 99e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct E : A {}; 109e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct F : D, E {}; 119e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redlstruct G : virtual D {}; 12651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesclass H : A {}; // expected-note 2{{implicitly declared private here}} 13f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 14f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint A::*pdi1; 15f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint (::A::*pdi2); 16f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint (A::*pfi)(int); 170e2c34f92f00628d48968dfea096d36381f494cbStephen Hinesvoid (*A::*ppfie)() throw(); // expected-error {{exception specifications are not allowed beyond a single level of indirection}} 18f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redl 1987d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainarint B::*pbi; 2087d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#if __cplusplus <= 199711L // C++03 or earlier modes 2187d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// expected-warning@-2 {{use of enumeration in a nested name specifier is a C++11 extension}} 2287d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar#endif 2387d948ecccffea9e9e37d0d053b246e2d6d6c47bPirama Arumuga Nainar// expected-error@-4 {{'pbi' does not point into a class}} 24f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlint C::*pci; // expected-error {{'pci' does not point into a class}} 25f30208ad5b334e93582e846a2a0c92f38a607b8aSebastian Redlvoid A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}} 268d4655d3b966da02fe0588767160448594cddd61Anders Carlssonint& A::*pdr; // expected-error {{'pdr' declared as a member pointer to a reference}} 278edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl 288edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redlvoid f() { 298edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl // This requires tentative parsing. 308edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl int (A::*pf)(int, int); 314433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl 324433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl // Implicit conversion to bool. 334433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl bool b = pdi1; 344433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl b = pfi; 354433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl 364433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl // Conversion from null pointer constant. 374433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl pf = 0; 384433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl pf = __null; 394433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl 404433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl // Conversion to member of derived. 414433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl int D::*pdid = pdi1; 424433aafbc2591b82e4ea2fc39c723b21d2497f4dSebastian Redl pdid = pdi2; 439e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redl 449e5e4aaf8b8835b552819d68d29b6d94115d8a0bSebastian Redl // Fail conversion due to ambiguity and virtuality. 457c2342dd4c9947806842e5aca3d2bb2e542853c9John 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':}} 467c2342dd4c9947806842e5aca3d2bb2e542853c9John 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}} 4721593acb933324b439bc68b68e7cc7d1c3e3484dSebastian Redl 4821593acb933324b439bc68b68e7cc7d1c3e3484dSebastian Redl // Conversion to member of base. 49d4eea8362605807327735727a9098abe1eb23b19Douglas Gregor pdi1 = pdid; // expected-error {{assigning to 'int A::*' from incompatible type 'int D::*'}} 5020b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor 5120b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor // Comparisons 5220b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor int (A::*pf2)(int, int); 5320b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor int (D::*pf3)(int, int) = 0; 5420b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor bool b1 = (pf == pf2); (void)b1; 5520b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor bool b2 = (pf != pf2); (void)b2; 5620b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor bool b3 = (pf == pf3); (void)b3; 5720b3e9918cf7d7845c920baabc4fb2f1ac0ee1d2Douglas Gregor bool b4 = (pf != 0); (void)b4; 588edef7c31d27fc9d5d163660702a8a7730a0d19fSebastian Redl} 59ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl 6033b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redlstruct TheBase 6133b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl{ 6233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void d(); 6333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl}; 6433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl 6533b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redlstruct HasMembers : TheBase 66ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl{ 67ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl int i; 68ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl void f(); 6933b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl 7033b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void g(); 7133b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void g(int); 7233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl static void g(double); 73ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl}; 74ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl 75ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redlnamespace Fake 76ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl{ 77ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl int i; 78ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl void f(); 79ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl} 80ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl 81ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redlvoid g() { 8233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl HasMembers hm; 8333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl 84ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl int HasMembers::*pmi = &HasMembers::i; 85ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl int *pni = &Fake::i; 8633b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl int *pmii = &hm.i; 87ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl 8833b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void (HasMembers::*pmf)() = &HasMembers::f; 89ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl void (*pnf)() = &Fake::f; 909c72c6088d591ace8503b842d39448c2040f3033John McCall &hm.f; // expected-error {{cannot create a non-constant pointer to member function}} 9133b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl 9233b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void (HasMembers::*pmgv)() = &HasMembers::g; 9333b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void (HasMembers::*pmgi)(int) = &HasMembers::g; 9433b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void (*pmgd)(double) = &HasMembers::g; 9533b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl 9633b399a8fdd0910ed86b60e61c6a02ba8258bbe3Sebastian Redl void (HasMembers::*pmd)() = &HasMembers::d; 97ebc07d57be9e0722b4b9c66625e1fca43dcc2ee0Sebastian Redl} 98224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 997d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregorstruct Incomplete; 1007878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl 101224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlvoid h() { 102224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl HasMembers hm, *phm = &hm; 103224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 104224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl int HasMembers::*pi = &HasMembers::i; 105224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl hm.*pi = 0; 106224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl int i = phm->*pi; 107224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl (void)&(hm.*pi); 108224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl (void)&(phm->*pi); 10927d4be5b3f455275ff6b6afe5ce155d6435081d7Fariborz Jahanian (void)&((&hm)->*pi); 110224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 111224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl void (HasMembers::*pf)() = &HasMembers::f; 112224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl (hm.*pf)(); 113224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl (phm->*pf)(); 1147878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl 1157c2342dd4c9947806842e5aca3d2bb2e542853c9John 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'}} 1167c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall (void)(phm.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'HasMembers *'}} 1177878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl (void)(i.*pi); // expected-error {{left hand operand to .* must be a class compatible with the right hand operand, but is 'int'}} 1187878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl int *ptr; 1197878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian 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 *'}} 1207878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl 1217878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl int A::*pai = 0; 1227878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl D d, *pd = &d; 1237878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl (void)(d.*pai); 1247878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl (void)(pd->*pai); 1257878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl F f, *ptrf = &f; 126651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines (void)(f.*pai); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}} 127651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines (void)(ptrf->*pai); // expected-error {{ambiguous conversion from derived class 'F' to base class 'A'}} 128651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines H h, *ptrh = &h; 129651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines (void)(h.*pai); // expected-error {{cannot cast 'H' to its private base class 'A'}} 130651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines (void)(ptrh->*pai); // expected-error {{cannot cast 'H' to its private base class 'A'}} 1317878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl 132e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor (void)(hm.*i); // expected-error {{pointer-to-member}} 133e7450f5dbd5bed63b8ef9db86350a8fc3db011e8Douglas Gregor (void)(phm->*i); // expected-error {{pointer-to-member}} 1347878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl 1357d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregor // Okay 1367878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl Incomplete *inc; 1377878ffde0c48a33a8fd3819be1b797d52f7b3849Sebastian Redl int Incomplete::*pii = 0; 1387d520baec9b762633a09d31ee0db12e41fe2758aDouglas Gregor (void)(inc->*pii); 139224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl} 140224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 141224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlstruct OverloadsPtrMem 142224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl{ 143224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl int operator ->*(const char *); 144224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl}; 145224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl 146224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redlvoid i() { 147224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl OverloadsPtrMem m; 148224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl int foo = m->*"Awesome!"; 149224605064a4ef87d1c3d35ad1cb363f8b534012bSebastian Redl} 150e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl 151e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redlnamespace pr5985 { 152e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl struct c { 153e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl void h(); 154e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl void f() { 155e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl void (c::*p)(); 156e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl p = &h; // expected-error {{must explicitly qualify}} 1579c72c6088d591ace8503b842d39448c2040f3033John McCall p = &this->h; // expected-error {{cannot create a non-constant pointer to member function}} 1589c72c6088d591ace8503b842d39448c2040f3033John McCall p = &(*this).h; // expected-error {{cannot create a non-constant pointer to member function}} 159e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl } 160e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl }; 161e27d87ff27b26e5886cf6472271d3b5e18ec3d87Sebastian Redl} 16217e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl 16317e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redlnamespace pr6783 { 16417e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl struct Base {}; 16517e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl struct X; // expected-note {{forward declaration}} 16617e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl 16717e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl int test1(int Base::* p2m, X* object) 16817e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl { 16917e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl return object->*p2m; // expected-error {{left hand operand to ->*}} 17017e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl } 17117e1d35848247cbc5ff31df58f0b67e85b64837cSebastian Redl} 172e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor 173e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregornamespace PR7176 { 174e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor namespace base 175e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor { 176e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor struct Process 177e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor { }; 178e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor struct Continuous : Process 179e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor { 180e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor bool cond(); 181e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor }; 182e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor } 183e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor 184e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor typedef bool( base::Process::*Condition )(); 185e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor 186e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor void m() 187e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor { (void)(Condition) &base::Continuous::cond; } 188e0d5fe2a417b84ac8b51927ebeb8f1c9ae492760Douglas Gregor} 1899c72c6088d591ace8503b842d39448c2040f3033John McCall 1909c72c6088d591ace8503b842d39448c2040f3033John McCallnamespace rdar8358512 { 1919c72c6088d591ace8503b842d39448c2040f3033John McCall // We can't call this with an overload set because we're not allowed 1929c72c6088d591ace8503b842d39448c2040f3033John McCall // to look into overload sets unless the parameter has some kind of 1939c72c6088d591ace8503b842d39448c2040f3033John McCall // function type. 1947114cbab7eb6e8b714eb22f014327daf2c741c08John McCall template <class F> void bind(F f); // expected-note 12 {{candidate template ignored}} 1959c72c6088d591ace8503b842d39448c2040f3033John McCall template <class F, class T> void bindmem(F (T::*f)()); // expected-note 4 {{candidate template ignored}} 1969c72c6088d591ace8503b842d39448c2040f3033John McCall template <class F> void bindfn(F (*f)()); // expected-note 4 {{candidate template ignored}} 1979c72c6088d591ace8503b842d39448c2040f3033John McCall 1989c72c6088d591ace8503b842d39448c2040f3033John McCall struct A { 1999c72c6088d591ace8503b842d39448c2040f3033John McCall void nonstat(); 2009c72c6088d591ace8503b842d39448c2040f3033John McCall void nonstat(int); 2019c72c6088d591ace8503b842d39448c2040f3033John McCall 2029c72c6088d591ace8503b842d39448c2040f3033John McCall void mixed(); 2039c72c6088d591ace8503b842d39448c2040f3033John McCall static void mixed(int); 2049c72c6088d591ace8503b842d39448c2040f3033John McCall 2059c72c6088d591ace8503b842d39448c2040f3033John McCall static void stat(); 2069c72c6088d591ace8503b842d39448c2040f3033John McCall static void stat(int); 2079c72c6088d591ace8503b842d39448c2040f3033John McCall 2089c72c6088d591ace8503b842d39448c2040f3033John McCall template <typename T> struct Test0 { 2099c72c6088d591ace8503b842d39448c2040f3033John McCall void test() { 2109c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&nonstat); // expected-error {{no matching function for call}} 2119c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&A::nonstat); // expected-error {{no matching function for call}} 2129c72c6088d591ace8503b842d39448c2040f3033John McCall 2139c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&mixed); // expected-error {{no matching function for call}} 2149c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&A::mixed); // expected-error {{no matching function for call}} 2159c72c6088d591ace8503b842d39448c2040f3033John McCall 2169c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&stat); // expected-error {{no matching function for call}} 2179c72c6088d591ace8503b842d39448c2040f3033John McCall bind(&A::stat); // expected-error {{no matching function for call}} 2189c72c6088d591ace8503b842d39448c2040f3033John McCall } 2199c72c6088d591ace8503b842d39448c2040f3033John McCall }; 2209c72c6088d591ace8503b842d39448c2040f3033John McCall 2219c72c6088d591ace8503b842d39448c2040f3033John McCall template <typename T> struct Test1 { 2229c72c6088d591ace8503b842d39448c2040f3033John McCall void test() { 2239c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&nonstat); // expected-error {{no matching function for call}} 2249c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&A::nonstat); 2259c72c6088d591ace8503b842d39448c2040f3033John McCall 2269c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&mixed); // expected-error {{no matching function for call}} 2279c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&A::mixed); 2289c72c6088d591ace8503b842d39448c2040f3033John McCall 2299c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&stat); // expected-error {{no matching function for call}} 2309c72c6088d591ace8503b842d39448c2040f3033John McCall bindmem(&A::stat); // expected-error {{no matching function for call}} 2319c72c6088d591ace8503b842d39448c2040f3033John McCall } 2329c72c6088d591ace8503b842d39448c2040f3033John McCall }; 2339c72c6088d591ace8503b842d39448c2040f3033John McCall 2349c72c6088d591ace8503b842d39448c2040f3033John McCall template <typename T> struct Test2 { 2359c72c6088d591ace8503b842d39448c2040f3033John McCall void test() { 2369c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&nonstat); // expected-error {{no matching function for call}} 2379c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&A::nonstat); // expected-error {{no matching function for call}} 2389c72c6088d591ace8503b842d39448c2040f3033John McCall 2399c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&mixed); // expected-error {{no matching function for call}} 2409c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&A::mixed); // expected-error {{no matching function for call}} 2419c72c6088d591ace8503b842d39448c2040f3033John McCall 2429c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&stat); 2439c72c6088d591ace8503b842d39448c2040f3033John McCall bindfn(&A::stat); 2449c72c6088d591ace8503b842d39448c2040f3033John McCall } 2459c72c6088d591ace8503b842d39448c2040f3033John McCall }; 2469c72c6088d591ace8503b842d39448c2040f3033John McCall }; 2477114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2487114cbab7eb6e8b714eb22f014327daf2c741c08John McCall template <class T> class B { 2497114cbab7eb6e8b714eb22f014327daf2c741c08John McCall void nonstat(); 2507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall void nonstat(int); 2517114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2527114cbab7eb6e8b714eb22f014327daf2c741c08John McCall void mixed(); 2537114cbab7eb6e8b714eb22f014327daf2c741c08John McCall static void mixed(int); 2547114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2557114cbab7eb6e8b714eb22f014327daf2c741c08John McCall static void stat(); 2567114cbab7eb6e8b714eb22f014327daf2c741c08John McCall static void stat(int); 2577114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // None of these can be diagnosed yet, because the arguments are 2597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // still dependent. 2607114cbab7eb6e8b714eb22f014327daf2c741c08John McCall void test0a() { 2617114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&nonstat); 2627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::nonstat); 2637114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&mixed); 2657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::mixed); 2667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&stat); 2687114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::stat); 2697114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 2707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall void test0b() { 2727114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&nonstat); // expected-error {{no matching function for call}} 2737114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::nonstat); // expected-error {{no matching function for call}} 2747114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2757114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&mixed); // expected-error {{no matching function for call}} 2767114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::mixed); // expected-error {{no matching function for call}} 2777114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2787114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&stat); // expected-error {{no matching function for call}} 2797114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bind(&B::stat); // expected-error {{no matching function for call}} 2807114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 2817114cbab7eb6e8b714eb22f014327daf2c741c08John McCall }; 2827114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 2837114cbab7eb6e8b714eb22f014327daf2c741c08John McCall template void B<int>::test0b(); // expected-note {{in instantiation}} 2849c72c6088d591ace8503b842d39448c2040f3033John McCall} 285b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor 286b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregornamespace PR9973 { 287b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor template<class R, class T> struct dm 288b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor { 289b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor typedef R T::*F; 290b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor F f_; 291b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor template<class U> int & call(U u) 2925acb0c98b363400f6ade0ae7250f0102224e806bJohn 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'}} 293b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor 294b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor template<class U> int operator()(U u) 295b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor { call(u); } // expected-note{{in instantiation of}} 296b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor }; 297b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor 298b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor template<class R, class T> 299b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor dm<R, T> mem_fn(R T::*) ; 300b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor 301b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor struct test 302b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor { int nullary_v(); }; 303b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor 304b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor void f() 305b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor { 306b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor test* t; 307b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor mem_fn(&test::nullary_v)(t); // expected-note{{in instantiation of}} 308b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor } 309b0844c6f07d8c9c6c9c3095201879593611b9e79Douglas Gregor} 310ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall 311ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCallnamespace test8 { 312ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall struct A { int foo; }; 313ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall int test1() { 314ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall // Verify that we perform (and check) an lvalue conversion on the operands here. 315ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall return (*((A**) 0)) // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} 316ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall ->**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} 317ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall } 318ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall 319ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall int test2() { 320ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall // Verify that we perform (and check) an lvalue conversion on the operands here. 321ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall // TODO: the .* should itself warn about being a dereference of null. 322ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall return (*((A*) 0)) 323ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall .**(int A::**) 0; // expected-warning {{indirection of non-volatile null pointer will be deleted}} expected-note {{consider}} 324ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall } 325ea4aba0e97ca71369a0f6e287443b670cf5c353fJohn McCall} 326