#include <stdio.h>
#include <cstring>
#include <cassert>
#include <typeinfo>
inline void
AssertIncompleteTypeInfoEquals(std::type_info const& LHS, std::type_info const& RHS)
{
assert(&LHS != &RHS);
assert(strcmp(LHS.name(), RHS.name()) == 0);
}
struct NeverDefined;
void ThrowNeverDefinedMP();
std::type_info const& ReturnTypeInfoNeverDefinedMP();
struct IncompleteAtThrow;
void ThrowIncompleteMP();
void ThrowIncompletePP();
void ThrowIncompletePMP();
std::type_info const& ReturnTypeInfoIncompleteMP();
std::type_info const& ReturnTypeInfoIncompletePP();
struct CompleteAtThrow;
void ThrowCompleteMP();
void ThrowCompletePP();
void ThrowCompletePMP();
std::type_info const& ReturnTypeInfoCompleteMP();
std::type_info const& ReturnTypeInfoCompletePP();
void ThrowNullptr();
#ifndef TU_ONE
void ThrowNeverDefinedMP() { throw (int NeverDefined::*)nullptr; }
std::type_info const& ReturnTypeInfoNeverDefinedMP() { return typeid(int NeverDefined::*); }
void ThrowIncompleteMP() { throw (int IncompleteAtThrow::*)nullptr; }
void ThrowIncompletePP() { throw (IncompleteAtThrow**)nullptr; }
void ThrowIncompletePMP() { throw (int IncompleteAtThrow::**)nullptr; }
std::type_info const& ReturnTypeInfoIncompleteMP() { return typeid(int IncompleteAtThrow::*); }
std::type_info const& ReturnTypeInfoIncompletePP() { return typeid(IncompleteAtThrow**); }
struct CompleteAtThrow {};
void ThrowCompleteMP() { throw (int CompleteAtThrow::*)nullptr; }
void ThrowCompletePP() { throw (CompleteAtThrow**)nullptr; }
void ThrowCompletePMP() { throw (int CompleteAtThrow::**)nullptr; }
std::type_info const& ReturnTypeInfoCompleteMP() { return typeid(int CompleteAtThrow::*); }
std::type_info const& ReturnTypeInfoCompletePP() { return typeid(CompleteAtThrow**); }
void ThrowNullptr() { throw nullptr; }
#else
struct IncompleteAtThrow {};
int main(int, char**) {
AssertIncompleteTypeInfoEquals(ReturnTypeInfoNeverDefinedMP(), typeid(int NeverDefined::*));
try {
ThrowNeverDefinedMP();
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (int CompleteAtThrow::*) {
assert(false);
} catch (int NeverDefined::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch NeverDefined::*" ); }
AssertIncompleteTypeInfoEquals(ReturnTypeInfoIncompleteMP(), typeid(int IncompleteAtThrow::*));
try {
ThrowIncompleteMP();
assert(false);
} catch (CompleteAtThrow**) {
assert(false);
} catch (int CompleteAtThrow::*) {
assert(false);
} catch (IncompleteAtThrow**) {
assert(false);
} catch (int IncompleteAtThrow::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch IncompleteAtThrow::*" ); }
AssertIncompleteTypeInfoEquals(ReturnTypeInfoIncompletePP(), typeid(IncompleteAtThrow**));
try {
ThrowIncompletePP();
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (IncompleteAtThrow** p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch IncompleteAtThrow**" ); }
try {
ThrowIncompletePMP();
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (IncompleteAtThrow**) {
assert(false);
} catch (int IncompleteAtThrow::**p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch IncompleteAtThrow::**" ); }
AssertIncompleteTypeInfoEquals(ReturnTypeInfoCompleteMP(), typeid(int CompleteAtThrow::*));
try {
ThrowCompleteMP();
assert(false);
} catch (IncompleteAtThrow**) {
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (CompleteAtThrow**) {
assert(false);
} catch (int CompleteAtThrow::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch CompleteAtThrow::" ); }
AssertIncompleteTypeInfoEquals(ReturnTypeInfoCompletePP(), typeid(CompleteAtThrow**));
try {
ThrowCompletePP();
assert(false);
} catch (IncompleteAtThrow**) {
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (int CompleteAtThrow::*) {
assert(false);
} catch (CompleteAtThrow**p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch CompleteAtThrow**" ); }
try {
ThrowCompletePMP();
assert(false);
} catch (IncompleteAtThrow**) {
assert(false);
} catch (int IncompleteAtThrow::*) {
assert(false);
} catch (int CompleteAtThrow::*) {
assert(false);
} catch (CompleteAtThrow**) {
assert(false);
} catch (int CompleteAtThrow::**p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch CompleteAtThrow::**" ); }
#if __cplusplus >= 201103L
try {
ThrowNullptr();
} catch (int IncompleteAtThrow::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch nullptr as IncompleteAtThrow::*" ); }
try {
ThrowNullptr();
} catch (int CompleteAtThrow::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch nullptr as CompleteAtThrow::*" ); }
try {
ThrowNullptr();
} catch (int NeverDefined::*p) {
assert(!p);
}
catch(...) { assert(!"FAIL: Didn't catch nullptr as NeverDefined::*" ); }
#endif
return 0;
}
#endif