namespace access_control {
class Private {
void check(int *) __attribute__((enable_if(false, "")));
void check(double *) __attribute__((enable_if(true, "")));
static void checkStatic(int *) __attribute__((enable_if(false, "")));
static void checkStatic(double *) __attribute__((enable_if(true, "")));
};
auto Priv = reinterpret_cast<void (Private::*)(char *)>(&Private::check);
auto PrivStatic = reinterpret_cast<void (*)(char *)>(&Private::checkStatic);
class Protected {
protected:
void check(int *) __attribute__((enable_if(false, "")));
void check(double *) __attribute__((enable_if(true, "")));
static void checkStatic(int *) __attribute__((enable_if(false, "")));
static void checkStatic(double *) __attribute__((enable_if(true, "")));
};
auto Prot = reinterpret_cast<void (Protected::*)(char *)>(&Protected::check);
auto ProtStatic = reinterpret_cast<void (*)(char *)>(&Protected::checkStatic); }
namespace unavailable {
void foo() __attribute__((unavailable("don't call this")));
void foo(int) __attribute__((enable_if(false, "")));
void *Ptr = reinterpret_cast<void*>(foo); }
namespace template_deduction {
void foo() __attribute__((enable_if(false, "")));
void bar() __attribute__((enable_if(true, "")));
void bar() __attribute__((enable_if(false, "")));
void baz(int a) __attribute__((enable_if(true, "")));
void baz(int a) __attribute__((enable_if(a, "")));
void baz(int a) __attribute__((enable_if(false, "")));
void qux(int a) __attribute__((enable_if(1, "")));
void qux(int a) __attribute__((enable_if(true, "")));
void qux(int a) __attribute__((enable_if(a, "")));
void qux(int a) __attribute__((enable_if(false, "")));
template <typename Fn, typename... Args> void call(Fn F, Args... As) {
F(As...);
}
void test() {
call(foo); call(bar);
call(baz, 0);
call(qux, 0);
auto Ptr1 = foo; auto Ptr2 = bar;
auto Ptr3 = baz;
auto Ptr4 = qux; }
template <typename Fn, typename T, typename... Args>
void callMem(Fn F, T t, Args... As) {
(t.*F)(As...);
}
class Foo {
void bar() __attribute__((enable_if(true, "")));
void bar() __attribute__((enable_if(false, "")));
static void staticBar() __attribute__((enable_if(true, "")));
static void staticBar() __attribute__((enable_if(false, "")));
};
void testAccess() {
callMem(&Foo::bar, Foo()); call(&Foo::staticBar); }
}
namespace template_template_deduction {
void foo() __attribute__((enable_if(false, "")));
template <typename T>
T foo() __attribute__((enable_if(true, "")));
template <typename Fn, typename... Args> auto call(Fn F, Args... As) {
return F(As...);
}
auto Ok = call(&foo<int>);
auto Fail = call(&foo);
auto PtrOk = &foo<int>;
auto PtrFail = &foo; }
namespace pointer_equality {
using FnTy = void (*)();
void bothEnableIf() __attribute__((enable_if(false, "")));
void bothEnableIf() __attribute__((enable_if(true, "")));
void oneEnableIf() __attribute__((enable_if(false, "")));
void oneEnableIf();
void test() {
FnTy Fn;
(void)(Fn == bothEnableIf);
(void)(Fn == &bothEnableIf);
(void)(Fn == oneEnableIf);
(void)(Fn == &oneEnableIf);
}
void unavailableEnableIf() __attribute__((enable_if(false, "")));
void unavailableEnableIf() __attribute__((unavailable("noooo")));
void testUnavailable() {
FnTy Fn;
(void)(Fn == unavailableEnableIf); (void)(Fn == &unavailableEnableIf); }
class Foo {
static void staticAccessEnableIf(); void accessEnableIf();
public:
static void staticAccessEnableIf() __attribute__((enable_if(false, "")));
void accessEnableIf() __attribute__((enable_if(false, "")));
};
void testAccess() {
FnTy Fn;
(void)(Fn == Foo::staticAccessEnableIf); (void)(Fn == &Foo::staticAccessEnableIf);
void (Foo::*MemFn)();
(void)(MemFn == &Foo::accessEnableIf); }
}