namespace pr37399 {
template <typename T>
struct Functor {
void (T::*PtrToMemberFunction)();
};
template <typename SomeType>
class SimpleDerivedFunctor;
template <typename SomeType>
class SimpleDerivedFunctor : public Functor<SimpleDerivedFunctor<SomeType>> {};
SimpleDerivedFunctor<void> SimpleFunctor;
short Global = 0;
template <typename SomeType>
class DerivedFunctor;
template <typename SomeType>
class DerivedFunctor
: public Functor<DerivedFunctor<void>> {
public:
void Foo() {
Global = 42;
}
};
class MultipleBase {
public:
MultipleBase() : Value() {}
short Value;
};
template <typename SomeType>
class MultiplyDerivedFunctor;
template <typename SomeType>
class MultiplyDerivedFunctor
: public Functor<MultiplyDerivedFunctor<void>>,
public MultipleBase {
public:
void Foo() {
MultipleBase::Value = 42*2;
}
};
class VirtualBase {
public:
VirtualBase() : Value() {}
short Value;
};
template <typename SomeType>
class VirtBaseFunctor
: public Functor<SomeType>,
public virtual VirtualBase{};
template <typename SomeType>
class VirtuallyDerivedFunctor;
template <typename SomeType>
class VirtuallyDerivedFunctor
: public VirtBaseFunctor<VirtuallyDerivedFunctor<void>>,
public virtual VirtualBase {
public:
void Foo() {
VirtualBase::Value = 42*3;
}
};
}
pr37399::DerivedFunctor<int> BFunctor;
pr37399::DerivedFunctor<void> AFunctor;
pr37399::MultiplyDerivedFunctor<int> DFunctor;
pr37399::MultiplyDerivedFunctor<void> CFunctor;
pr37399::VirtuallyDerivedFunctor<int> FFunctor;
pr37399::VirtuallyDerivedFunctor<void> EFunctor;
namespace pr37399 {
void SingleInheritanceFnPtrCall() {
BFunctor.PtrToMemberFunction = &DerivedFunctor<void>::Foo;
(AFunctor.*(BFunctor.PtrToMemberFunction))();
}
void MultipleInheritanceFnPtrCall() {
DFunctor.PtrToMemberFunction = &MultiplyDerivedFunctor<void>::Foo;
Global = CFunctor.MultipleBase::Value;
(CFunctor.*(DFunctor.PtrToMemberFunction))();
Global = CFunctor.MultipleBase::Value;
}
void VirtualInheritanceFnPtrCall() {
FFunctor.PtrToMemberFunction = &VirtuallyDerivedFunctor<void>::Foo;
Global = EFunctor.VirtualBase::Value;
(EFunctor.*(FFunctor.PtrToMemberFunction))();
Global = EFunctor.VirtualBase::Value;
}
}
namespace pr43803 {
struct B;
struct C { int B::*option; };
extern const C table[3];
struct A {
int x, y;
struct {
int z;
};
};
struct B : A {};
const C table[] = {
{&B::x},
{&B::y},
{&B::z},
};
}
namespace pr48687 {
template <typename T> struct A {
T value;
static constexpr auto address = &A<T>::value;
};
extern template class A<float>;
template class A<float>;
}
struct PR26313_Y;
typedef void (PR26313_Y::*PR26313_FUNC)();
struct PR26313_X {
PR26313_FUNC *ptr;
PR26313_X();
};
PR26313_X::PR26313_X() {}
void PR26313_f(PR26313_FUNC *p) { delete p; }
struct PR26313_Z;
int PR26313_Z::**a = nullptr;
int PR26313_Z::*b = *a;
namespace PR20947 {
struct A;
int A::**a = nullptr;
struct B;
int B::*&b = b;
}
namespace PR20017 {
template <typename T>
struct A {
int T::*m_fn1() { return nullptr; }
};
struct B;
auto a = &A<B>::m_fn1;
}
#ifndef INCOMPLETE_VIRTUAL
struct B1 {
void foo();
int b;
};
struct B2 {
int b2;
void foo();
};
struct Single : B1 {
void foo();
};
struct Multiple : B1, B2 {
int m;
void foo();
};
struct Virtual : virtual B1 {
int v;
void foo();
};
struct POD {
int a;
int b;
};
struct Polymorphic {
virtual void myVirtual();
int a;
int b;
};
struct NonZeroVBPtr : POD, Virtual {
int n;
void foo();
};
struct Unspecified;
struct UnspecSingle;
int Single ::*s_d_memptr;
int Polymorphic::*p_d_memptr;
int Multiple ::*m_d_memptr;
int Virtual ::*v_d_memptr;
int NonZeroVBPtr::*n_d_memptr;
int Unspecified::*u_d_memptr;
int UnspecSingle::*us_d_memptr;
void (Single ::*s_f_memptr)();
void (Multiple::*m_f_memptr)();
void (Virtual ::*v_f_memptr)();
struct Unspecified : Multiple, Virtual {
void foo();
int u;
};
struct UnspecSingle {
void foo();
};
namespace Const {
void (Single ::*s_f_mp)() = &Single::foo;
void (Multiple ::*m_f_mp)() = &B2::foo;
void (Virtual ::*v_f_mp)() = &Virtual::foo;
void (Unspecified::*u_f_mp)() = &Unspecified::foo;
void (UnspecSingle::*us_f_mp)() = &UnspecSingle::foo;
}
namespace CastParam {
struct A {
int a;
void foo(A *p);
};
struct B { int b; };
struct C : B, A { int c; };
void (A::*ptr1)(void *) = (void (A::*)(void *)) &A::foo;
void (C::*ptr2)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) &A::foo;
void (C::*ptr3)(void *) = (void (C::*)(void *)) (void (A::*)(void *)) (void (A::*)(A *)) 0;
struct D : C {
virtual void isPolymorphic();
int d;
};
int C::*ptr4 = (int C::*) (int D::*) (long D::*) 0;
int C::*ptr5 = (int C::*) (long D::*) 0;
}
struct UnspecWithVBPtr;
int UnspecWithVBPtr::*forceUnspecWithVBPtr;
struct UnspecWithVBPtr : B1, virtual B2 {
int u;
void foo();
};
void EmitNonVirtualMemberPointers() {
void (Single ::*s_f_memptr)() = &Single::foo;
void (Multiple ::*m_f_memptr)() = &Multiple::foo;
void (Virtual ::*v_f_memptr)() = &Virtual::foo;
void (Unspecified::*u_f_memptr)() = &Unspecified::foo;
void (UnspecWithVBPtr::*u2_f_memptr)() = &UnspecWithVBPtr::foo;
}
void podMemPtrs() {
int POD::*memptr;
memptr = &POD::a;
memptr = &POD::b;
if (memptr)
memptr = 0;
}
void polymorphicMemPtrs() {
int Polymorphic::*memptr;
memptr = &Polymorphic::a;
memptr = &Polymorphic::b;
if (memptr)
memptr = 0;
}
bool nullTestDataUnspecified(int Unspecified::*mp) {
return mp;
}
bool nullTestFunctionUnspecified(void (Unspecified::*mp)()) {
return mp;
}
int loadDataMemberPointerVirtual(Virtual *o, int Virtual::*memptr) {
return o->*memptr;
}
int loadDataMemberPointerUnspecified(Unspecified *o, int Unspecified::*memptr) {
return o->*memptr;
}
void callMemberPointerSingle(Single *o, void (Single::*memptr)()) {
(o->*memptr)();
}
void callMemberPointerMultiple(Multiple *o, void (Multiple::*memptr)()) {
(o->*memptr)();
}
void callMemberPointerVirtualBase(Virtual *o, void (Virtual::*memptr)()) {
(o->*memptr)();
}
bool compareSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
return l == r;
}
bool compareNeqSingleFunctionMemptr(void (Single::*l)(), void (Single::*r)()) {
return l != r;
}
bool unspecFuncMemptrEq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
return l == r;
}
bool unspecFuncMemptrNeq(void (Unspecified::*l)(), void (Unspecified::*r)()) {
return l != r;
}
bool unspecDataMemptrEq(int Unspecified::*l, int Unspecified::*r) {
return l == r;
}
void (Multiple::*convertB2FuncToMultiple(void (B2::*mp)()))() {
return mp;
}
void (B2::*convertMultipleFuncToB2(void (Multiple::*mp)()))() {
return static_cast<void (B2::*)()>(mp);
}
namespace Test1 {
struct A { int a; };
struct B { int b; };
struct C : virtual A { int c; };
struct D : B, C { int d; };
void (D::*convertCToD(void (C::*mp)()))() {
return mp;
}
}
namespace Test2 {
struct A { int a; };
struct B : A { int b; };
struct C : A {
int c;
virtual void hasVfPtr();
};
int A::*reinterpret(int B::*mp) {
return reinterpret_cast<int A::*>(mp);
}
int A::*reinterpret(int C::*mp) {
return reinterpret_cast<int A::*>(mp);
}
}
namespace Test3 {
struct A {
int a;
int b;
};
int *load_data(A *a, int A::*mp) {
return &(a->*mp);
}
}
namespace Test4 {
struct A { virtual void f(); };
struct B { virtual void g(); };
struct C : A, B { virtual void g(); };
void (C::*getmp())() {
return &C::g;
}
}
namespace pr20007 {
struct A {
void f();
void f(int);
};
struct B : public A {};
void test() { void (B::*a)() = &B::f; }
}
namespace pr20007_kw {
struct A {
void f();
void f(int);
};
struct __single_inheritance B;
struct B : public A {};
void test() { void (B::*a)() = &B::f; }
}
namespace pr20007_pragma {
struct A {
void f();
void f(int);
};
struct B : public A {};
void test() { (void)(void (B::*)()) &B::f; }
#pragma pointers_to_members(full_generality, virtual_inheritance)
static_assert(sizeof(int B::*) == 4, "");
static_assert(sizeof(int A::*) == 4, "");
#pragma pointers_to_members(best_case)
}
namespace pr20007_pragma2 {
struct A {
};
struct B : public A {
void f();
};
void test() { (void)&B::f; }
#pragma pointers_to_members(full_generality, virtual_inheritance)
static_assert(sizeof(int B::*) == 4, "");
static_assert(sizeof(int A::*) == 12, "");
#pragma pointers_to_members(best_case)
}
namespace pr23823 {
struct Base { void Method(); };
struct Child : Base {};
void use(void (Child::*const &)());
void f() { use(&Child::Method); }
#pragma pointers_to_members(full_generality, virtual_inheritance)
static_assert(sizeof(int Base::*) == 4, "");
static_assert(sizeof(int Child::*) == 4, "");
#pragma pointers_to_members(best_case)
}
namespace pr19987 {
template <typename T>
struct S {
int T::*x;
};
struct U : S<U> {};
static_assert(sizeof(S<U>::x) == 12, "");
}
#else
struct __virtual_inheritance A;
#ifdef MEMFUN
int foo(A *a, int (A::*mp)()) {
return (a->*mp)(); }
#else
int foo(A *a, int A::*mp) {
return a->*mp; }
#endif
#endif
namespace pr23878 {
struct A { virtual void g(); };
struct B { virtual void f(); };
struct C : virtual B { void f(); };
struct D : A, C {};
typedef void (D::*DMemPtrTy)();
DMemPtrTy get_memptr() { return &D::f; }
}
class C {};
typedef void (C::*f)();
class CA : public C {
public:
void OnHelp(void);
int OnHelp(int);
};
void foo_fun() {
f func = (f)&CA::OnHelp;
}
namespace PR24703 {
struct S;
void f(int S::*&p) {}
}
namespace ReferenceToMPTWithIncompleteClass {
struct S;
struct J;
struct K;
extern K *k;
unsigned f(int S::*&p) { return sizeof p; }
bool g(int J::*&p, int J::*&q) { return p == q; }
int h(int K::*&p) { return k->*p; }
}
namespace PMFInTemplateArgument {
template <class C, int (C::*M)(int)>
void JSMethod();
class A {
int printd(int);
void printd();
};
void A::printd() { JSMethod<A, &A::printd>(); }
}